Page 1 of 1
Updating UserVariable based on Domoticz device
Posted: Wednesday 08 November 2017 8:25
by TacticalLeader
Dear Domoticzers,
I'm sorry if it was answered before, but i just can't find how to update a user variable based on a device value. I'd like to use DzVents scripts, be i'm stucked with it. Could you please help me out with this?
Thank you very much & have a nice day!
Re: Updating UserVariable based on Domoticz device
Posted: Wednesday 08 November 2017 8:32
by emme
try with
Code: Select all
return {
on = {
devices = {
'myDevice'
}
},
execute = function(domoticz, device)
domoticz.variables('myVar').set(device.rawData[1])
end
}
Re: Updating UserVariable based on Domoticz device
Posted: Wednesday 08 November 2017 9:23
by TacticalLeader
Thank you very much, it is working now.
I didn't know I have to add the rawData[1] after .set
I added +0.5 and -0.5 and it is working too. Let me ask another question. How to add a UserVariable to the rawData, to change the 0.5 easier?
This is the code now,
Code: Select all
domoticz.variables('sp_hysteresis_down').set(device.rawData[1]-0.5)
domoticz.variables('sp_hysteresis_up').set(device.rawData[1]+0.5)
And I'd like to do this:
Code: Select all
domoticz.variables('sp_hysteresis_down').set(device.rawData[1]-domoticz.variables('sp_hysteresis'))
domoticz.variables('sp_hysteresis_up').set(device.rawData[1]+domoticz.variables('sp_hysteresis'))
And I'd like to set the sp_hysteresis in user variables by hand.
Re: Updating UserVariable based on Domoticz device
Posted: Thursday 09 November 2017 8:46
by emme
mmh... it looks like a quite wired script...
could you explain exactly what you want to achieve?
who are the involved actors (devices, variables, switches etc etc...)?
ciao
M
Re: Updating UserVariable based on Domoticz device
Posted: Thursday 09 November 2017 11:38
by TacticalLeader
emme wrote: ↑Thursday 09 November 2017 8:46
mmh... it looks like a quite wired script...
could you explain exactly what you want to achieve?
who are the involved actors (devices, variables, switches etc etc...)?
ciao
M
I have 6 rooms & 6 temperature sensors & 6 virtual thermostats. I'd like to add a hysteresis to the thermostats based on UserVariable 'sp_hysteresis' to achieve an independent heating control for each room based on the virtual thermostats' timers.
I have DzVents scripts now, like this:
Code: Select all
return {
on = {
devices = {
'Setpoint - Living room'
}
},
execute = function(domoticz, device)
domoticz.variables('sp_living_hysteresis_up').set(device.rawData[1]+0.5)
domoticz.variables('sp_living_hysteresis_down').set(device.rawData[1]-0.5)
end
}
I'd like to add and substract the value of hysteresis by replacing the +0.5 and -0.5 with the UserVariable 'sp_hysteresis'. Hope it is understandable now

The timers are set in the virtual thermostats.
Re: Updating UserVariable based on Domoticz device
Posted: Thursday 09 November 2017 12:06
by emme
Code: Select all
return {
on = {
devices = {
'Setpoint - Living room'
},
variables = {
'sp_hysteresis'
},
},
execute = function(domoticz, deviceOrVariable)
local hysteresis = domoticz.variables('sp_hysteresis').value
domoticz.variables('sp_living_hysteresis_up').set(device.rawData[1]+hysteresis)
domoticz.variables('sp_living_hysteresis_down').set(device.rawData[1]-hysteresis)
end
}
so... in case you change Setpoint - Living room your sp_living_hysteresis_up an sp_living_hysteresis_down will be updated
as well as in case you change the variable sp_hysteresis both _up and _down will be updated