Homeyscript lose varibles after reboot

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.

Like this ?

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 :wink: run a script at startup that sets each variable to a default value.

Yes. But I dont know how that script shall look like :cry:

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:

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!

1 Like