I use Homeyscript for helping me find numbers in JSON MQTT messages.
Then use those varibles to set values to virtual sensors.
But after every reboot the varibles from my flows settings are gone (greyed out)
For fixing that I have to remove the varible from each flow push test and then I can insert the varible again.
I use approx 15 flows with this so it would be nice if it can be fixed, or can I do it myself ?
Doesnât âgreyed outâ mean that they havenât yet been assigned a value (since the reboot)? In that case, you may be able to run a flow triggered on âHomey has startedâ that will run a script to populate the values.
Thats probaly true. But what command or flow can do that?
I have a flow card that translates to âHomey has startedâ. Perhaps you need to enable the Power User experiment for that in the mobile app settings.
That action would trigger a script that youâd have to create that will populate the variables to a default value.
Found the â Homey has startedâ but how do I set the variables ? I cant see the variables after reboot under Tags
Use the âHomey as startedâ trigger to run a (Homey)script that will set the variables.
In your initial post youâre writing that youâre using Homeyscript âfor helping me find numbers in JSON MQTT messages. Then use those varibles to set values to virtual sensorsâ.
So the Homeyscript you mention sets those variables, correct? In that case, you can create a new Homeyscript, that gets run at startup, that will set those variables to a default value (but like I said before, I canât promise that that will solve your problem; however, itâs worth trying).
I donât know why youâre showing a flow card.
Yes they are set by homeyscript. The flow I posted shows a flow that should run after Homey started.
I tought that how it should be done. IF I do I homeyscript that sets those variables must be started from a flow ?
I am not a programmer, how should a Homeyscript look like that sets variables ?
Canât you force running the Homeyscript youâre already using at startup?
Dont think so. Its a script for each topic that needed for each sensor. The best thing I think would be if I could set each variable in a startup script.
Somerhing like:
Set varible WDHUM = 99.9
Set variable WDTEMP = 99.9
Ser variable WDRAIN = 99.9
And so on.
So that my flows have these values and variables already when the flow runs the first time.
But I dont know if that solves the problem
Thatâs what Iâve basically been trying to suggest run a script at startup that sets each variable to a default value.
Yes. But I dont know how that script shall look like
You already have a script, donât you? What does that look like?
Here is how the script look like for âconvertingâ JSON to NUM and set variable
This gets me the RainNum varible
// my script
var MyNum = parseFloat(args[0].match(/[\d.-]+/)[0]);
await setTagValue(âRainNumâ, {type: ânumberâ, title: âRainNumâ}, MyNum);
return true
So something like this:
await setTagValue('RainNum', {type: 'number', title: 'RainNum'}, 99.9);
await setTagValue('TempNum', {type: 'number', title: 'TempNum'}, 99.9);
await setTagValue('HumNum', {type: 'number', title: 'HumNum'}, 99.9);
Where you would replace the names with the correct variable names (Iâm just guessing the names) and use a reasonable default value.
Thanks @robertklep !!
Tested the script and got this mesage:
Script returned:
undefined
Is that right?
This is the code in my script:
// my script
await setTagValue(âwdhumâ, {type: ânumberâ, title: âwdhumâ}, 99.9);
await setTagValue(âwdtempâ, {type: ânumberâ, title: âwdtempâ}, 99.9);
await setTagValue(âRainNumâ, {type: ânumberâ, title: âRainNumâ}, 99.9);
await setTagValue(âftempNumâ, {type: ânumberâ, title: âftempNumâ}, 99.9);
await setTagValue(âfthumNumâ, {type: ânumberâ, title: âfthumNumâ}, 99.9);
await setTagValue(âgrtempâ, {type: ânumberâ, title: âgrtempâ}, 99.9);
await setTagValue(âgrhumâ, {type: ânumberâ, title: âgrhumâ}, 99.9);
await setTagValue(âvrtempâ, {type: ânumberâ, title: âvrtempâ}, 99.9);
await setTagValue(âvrhumâ, {type: ânumberâ, title: âvrhumâ}, 99.9);
await setTagValue(âwdapptâ, {type: ânumberâ, title: âwdapptâ}, 99.9);
await setTagValue(âwdcwindâ, {type: ânumberâ, title: âwdcwindâ}, 99.9);
await setTagValue(âwdmwtâ, {type: ânumberâ, title: âwdmwtâ}, 99.9);
I donât think it matters what the script returns, but you could add a return true
at the end of it.
Runned it and every variable was set set to 99.9 so it seems to work.
Just to be sureâŚ
I now created a flow that looks like this. Is this right?
Looks good to me!