Page 1 of 1
User Variables vs persistent variables
Posted: Friday 25 August 2017 17:51
by randytsuch
So I prefer using persistent variables, it's easier and cleaner, keeps everything together.
But I don't know how to update persistent, or even global variables from an app.
With global variables, I can update them from my android or wife's iphone app.
I've set up things like sprinkler run times and thermostat temps and mode as user variables so I can set them from anywhere.
Just wondering if there is a way to set global variables from an app?
Randy
Re: User Variables vs persistent variables
Posted: Friday 25 August 2017 18:23
by BakSeeDaa
Sure you can.
Make a dzVents script that changes the dzVents
global persistent variable for you. Let the script triggering on the change of a variable or a Domoticz device. A text text sensor will be perfect for the purpose. Then make your app change that text device by calling an
Domoticz API/JSON URL. Piece of cake. Let me know if you need to know exacly how a dzVents script like that would look like!
PS. If You don't want to see that text device among your other devices, just rename it with a $ sign in front of its name.
Re: User Variables vs persistent variables
Posted: Friday 25 August 2017 21:25
by randytsuch
So I think you're saying I can use my browser to make a http call to set a dummy text switch, and then for example, use that for the temperature for my thermostat. Then I make a bookmark with that http address. I guess the only problem is you would have to edit if you didn't like the default temp. But I should be able to make a summer temp and a winter temp that works most of the time.
Cool, thanks for the idea.
I'll see if I can figure out the rest of how to do this with the tutorial, google and my limited sw skills lol
Randy
Re: User Variables vs persistent variables
Posted: Saturday 26 August 2017 9:01
by BakSeeDaa
Yes you can use a browser to do the http call and manually enter the value in the URL or you could another app to make the http call for you.
Tasker is a nice app for example.
If you don't need to see the new value in the GUI it's better to use a user variable than a virtual text sensor. When you create the user variable, you can choose "Float" as type if you intend to use it for temperatures.
dzVents comes with some templates that you can base your script on.
This could be a start:
Code: Select all
return {
active = true,
on = {
variables = {
'myUserVariable'
}
},
execute = function(domoticz, variable)
domoticz.log('Variable ' .. variable.name .. ' was changed', domoticz.LOG_INFO)
-- Set the thermostat here!
end
}
And here is the URL according to the
documentation.
Code: Select all
/json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE
Where type is 0 to 4:
Code: Select all
0 = Integer, e.g. -1, 1, 0, 2, 10
1 = Float, e.g. -1.1, 1.2, 3.1
2 = String
3 = Date in format DD/MM/YYYY
4 = Time in 24 hr format HH:MM
5 = DateTime (but the format is not checked)