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!
Updating UserVariable based on Domoticz device
Moderator: leecollings
-
- Posts: 13
- Joined: Tuesday 19 January 2016 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Szeged, Hungary
- Contact:
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Updating UserVariable based on Domoticz device
try with
Code: Select all
return {
on = {
devices = {
'myDevice'
}
},
execute = function(domoticz, device)
domoticz.variables('myVar').set(device.rawData[1])
end
}
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 13
- Joined: Tuesday 19 January 2016 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Szeged, Hungary
- Contact:
Re: Updating UserVariable based on Domoticz device
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,
And I'd like to do this:
And I'd like to set the sp_hysteresis in user variables by hand.
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)
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'))
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Updating UserVariable based on Domoticz device
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
could you explain exactly what you want to achieve?
who are the involved actors (devices, variables, switches etc etc...)?
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 13
- Joined: Tuesday 19 January 2016 13:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Szeged, Hungary
- Contact:
Re: Updating UserVariable based on Domoticz device
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
}

- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Updating UserVariable based on Domoticz device
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
}
as well as in case you change the variable sp_hysteresis both _up and _down will be updated
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
Who is online
Users browsing this forum: Google [Bot] and 1 guest