Lua virtual device thermostat device change

433Mhz opensource Receiver & Transmitter.

Moderators: leecollings, Stuntteam

Post Reply
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Lua virtual device thermostat device change

Post 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
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua virtual device thermostat device change

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Lua virtual device thermostat device change

Post 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.
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua virtual device thermostat device change

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Lua virtual device thermostat device change

Post 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
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua virtual device thermostat device change

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Lua virtual device thermostat device change

Post by Chakkie »

jvdz

YOU ARE AWESOME.

Thanks a lot.

I though DeviceChanged only respons to 'On' or 'Off'
kimot
Posts: 105
Joined: Saturday 25 November 2017 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: Lua virtual device thermostat device change

Post 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
}
RPi2 Domoticz v 4.10717
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest