Page 1 of 1
Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 11:04
by Chakkie
Hi everyone,
I was wonder if Device Change command in Lua also applicable to the virtual device in thermostat type.
For example I would like to turn on a switch / light / or something if the set temperature of the thermostat has been changed.
Some thing like
if Device thermostat = "changed" then
Commandarray = switch == On
Or is there other suggestion ?
thanks
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 11:16
by jvdz
That should work fine. Did you actually give it a try to see what happens as the shown code doesn't have the proper syntax?
Jos
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 11:59
by Chakkie
Thanks jvdz. No I have not tried it yet. It was just a quick type example. And I don't know the proper syntax either. I could not find the correct syntax for the device change. The wiki page only show the example of device change == on. That's why I was wondering if my idea was possible.
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 12:20
by jvdz
This would be a good point to start in case you want to write LUA scripts:
https://www.domoticz.com/wiki/Events
Jos
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 12:28
by Chakkie
I did something like this but does not work
--Thermostat setpoint
local WNKT = '1 thermostat'
local HSLPT = '2 Thermostat'
local KLNKT = '3 thermostat'
--Maxscript (Virtual switch)
local Max ="Maxscript"
commandArray = {}
if (devicechanged[WKT] == true or devicechanged[HSLPT] == true or devicechanged[KLNKT] == true) then
print('Run Maxscript')
commandArray[Max]='On AFTER 3'
end
return commandArray
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 12:50
by jvdz
The devicechanged table will contain the device(s) changed and their new value while you compare them to true.
try:
Code: Select all
- Thermostat setpoint
local WNKT = '1 thermostat'
local HSLPT = '2 Thermostat'
local KLNKT = '3 thermostat'
--Maxscript (Virtual switch)
local Max = "Maxscript"
commandArray = {}
if (devicechanged[WKT] or devicechanged[HSLPT] or devicechanged[KLNKT]) then
print('Run Maxscript')
commandArray[Max] = 'On AFTER 3'
end
return commandArray
Jos
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 12:59
by Chakkie
jvdz
YOU ARE AWESOME.
Thanks a lot.
I though DeviceChanged only respons to 'On' or 'Off'
Re: Lua virtual device thermostat device change
Posted: Saturday 09 December 2017 15:53
by kimot
Hi.
I am using thermostat too.
Here is my examples of my action, if thermostat setpoint is changed.
In my case, it sends command to my device with setpoint value, but you can write your own action.
LUA:
Code: Select all
commandArray = {}
if devicechanged['Kacka_Setpoint'] then
DomDevice = 'Kacka_Setpoint'
DomValue = otherdevices_svalues[DomDevice]
CalcValue = (DomValue*1)
print(CalcValue)
url= 'http://192.168.1.102/control?cmd=event,HeatSetpoint='..(CalcValue)..''
print(url)
commandArray['OpenURL']= url
end
return commandArray
But I prefer dzVents now:
Code: Select all
return {
active = true, -- set to false to disable this script
on = {
devices = {
'Kacka_Setpoint'
}
},
execute = function(domoticz, device)
local url= 'http://192.168.1.102/control?cmd=event,HeatSetpoint='..(device.state)..''
print(url)
domoticz.openURL(url)
end
}