Updating UserVariable based on Domoticz device

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
TacticalLeader
Posts: 13
Joined: Tuesday 19 January 2016 13:19
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Szeged, Hungary
Contact:

Updating UserVariable based on Domoticz device

Post 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!
User avatar
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

Post by emme »

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"
TacticalLeader
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

Post 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.
User avatar
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

Post 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
The most dangerous phrase in any language is:
"We always done this way"
TacticalLeader
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

Post 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 :roll: The timers are set in the virtual thermostats.
User avatar
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

Post 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
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest