dzVents multiple setpoint updates through ImperiHome

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

Moderator: leecollings

Post Reply
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

dzVents multiple setpoint updates through ImperiHome

Post by MikeF »

I'm using ImperiHome via MyDomoAtHome with Domoticz, and I'm using a dzVents script to update my Hive Heating system whenever I tap on a setpoint widget in ImperiHome.

Trouble is, IH has no 'Set' button, unlike the Domoticz setpoint device, so every time I tap the up or down arrows, it fires the dzVents script. Is there any way of making the script pause and wait for further taps (e.g., max. 2 seconds), so that it only updates Domoticz - and my Hive system - only once (on the last tap)?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents multiple setpoint updates through ImperiHome

Post by waaren »

MikeF wrote: Friday 04 January 2019 19:23 I'm using ImperiHome via MyDomoAtHome with Domoticz, and I'm using a dzVents script to update my Hive Heating system whenever I tap on a setpoint widget in ImperiHome.

Trouble is, IH has no 'Set' button, unlike the Domoticz setpoint device, so every time I tap the up or down arrows, it fires the dzVents script. Is there any way of making the script pause and wait for further taps (e.g., max. 2 seconds), so that it only updates Domoticz - and my Hive system - only once (on the last tap)?
In theory that is possible but you don't want to implement it like that because the event system in domoticz is single threaded. An implementation with a repeated pause in a script would block the entire event system for the duration of the script. Most likely there are ways to work around that and implement it in a asynchronous way. If you share your current script here I might be able to comment/ help in a more useful way.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: dzVents multiple setpoint updates through ImperiHome

Post by MikeF »

What I've actually done is to create a 'hybrid' lua / python solution. In Domoticz I have the following devices:
- a setpoint ('Setpoint')
- an on / off switch ('Heating boost')
- a selector switch ('Heating mode' - Off / Schedule / Manual)
The lua script checks these devices, and also runs a timer (every minute), and sends arguments to my python script, which does the heavy lifting of updating my Hive system or reading values from it. (This is based on scripts in my 'Read British Gas Hive Heating temperature' thread.)
The lua script is here:
Spoiler: show

Code: Select all

-- dzVents script to pass Hive heating arguments to python script

return {
    on = { 	devices = { "Heating boost", "Setpoint", "Heating mode" },
			timer = { "every minute"}
    }, 

    execute = function(dz, item)

        local arg = ""
        if (item.isTimer) then
        	arg = "read:"
        elseif (item.isDevice and item.name == "Heating boost") then
        	arg = "boost:" .. item.state
        elseif (item.isDevice and item.name == "Setpoint") then
        	arg = "set:" .. item.setPoint
        elseif (item.isDevice and item.name == "Heating mode") then
        	arg = "mode:" .. item.rawData[1]
        end

        local py_script = 'python /home/pi/devices/hive_heating.py '

		local cmd = py_script .. arg 
		--print(cmd)
		os.execute(cmd)

    end
}
The relevant part of the python script is here:
Spoiler: show

Code: Select all

elif cmd == "set":

	#update setpoint
	
	if setpoint < 5: setpoint = 5
	if setpoint > 32: setpoint = 32

	if r_mode == "Off":
		payload = {"mode": "SCHEDULE", "target": setpoint}
	else:
		payload = {"target": setpoint}

	headers = {'authorization': sessionId}
	url = 'https://beekeeper-uk.hivehome.com/1.0/nodes/heating/' + nodeId
	r = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)
(I can include the complete script if appropriate.)

Changing setpoint works fine in Domoticz (as it's only activated once when you click on 'Set' on the Setpoint device), but not in ImperiHome, as each tap on an up /down arrow (to set a significantly different temperature) is read by Domoticz, which causes the dzVents script to be activated multiple times.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents multiple setpoint updates through ImperiHome

Post by waaren »

waaren wrote: Saturday 05 January 2019 0:22
MikeF wrote: Friday 04 January 2019 23:30 What I've actually done is to create a 'hybrid' lua / python solution. In Domoticz I have the following devices:
- a setpoint ('Setpoint')
- an on / off switch ('Heating boost')
- a selector switch ('Heating mode' - Off / Schedule / Manual)
The lua script checks these devices, and also runs a timer (every minute), and sends arguments to my python script, which does the heavy lifting of updating my Hive system or reading values from it. (This is based on scripts in my 'Read British Gas Hive Heating temperature' thread.)

Changing setpoint works fine in Domoticz (as it's only activated once when you click on 'Set' on the Setpoint device), but not in ImperiHome, as each tap on an up /down arrow (to set a significantly different temperature) is read by Domoticz, which causes the dzVents script to be activated multiple times.
Understand. Would it be an option to remove Setpoint from the "on = devices" table and modify the dzVents script in such a way that in the timer part of the script a changed setPoint is recognized and acted upon ? That would be an easy "fix" (see script below) but will cause the setPoint update to be delayed for max. 1 minute for both domoticz GUI and ImperiHome initiated setPoint changes.
If that would be unacceptable for the domoticz triggered part you would have to introduce a virtual setPoint device to register the domoticz initiated changes. Script will become a bit more complex and the exact type of the current setpoint device must be known, as it would be needed to also update it by the script. (virtual setpoint setting -> real setpoint setting)

Code: Select all

-- dzVents script to pass Hive heating arguments to python script

local boost     = "Heating boost"
local mode      = "Heating mode"

return {
            on  =   { 
                        devices = { boost,mode      },  
                        timer   = { "every minute"  }
                    }, 

            data =  {  
                       setPoint = { initial = 0             } 
                    } ,
    
    execute = function(dz, item)
        
        local arg               = ""
        local setPointDevice    = dz.devices("Setpoint")
        local setPoint          = setPointDevice.setPoint
        
        if item.isTimer then
            if dz.data.setPoint ~= setPoint then
                dz.data.setPoint = setPoint
                arg = "set:" .. setPoint      
            else    
                arg = "read:"
            end
        elseif item.name == boost then
        	arg = "boost:" .. item.state
        elseif item.name == mode  then
        	arg = "mode:" .. item.rawData[1]
        end

        local py_script = 'python /home/pi/devices/hive_heating.py '

		local cmd = py_script .. arg 
		-- print(cmd)
		os.execute(cmd)

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: dzVents multiple setpoint updates through ImperiHome

Post by MikeF »

Many thanks for this. I'm not sure what you mean by creating a virtual setpoint device? I currently have a setpoint device (called 'Setpoint') in the Utilities tab, and when this is changed in the Domoticz GUI, or in ImperiHome, the lua script calls the python script, which then changes the real Hive thermostat by invoking the Hive JSON API.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents multiple setpoint updates through ImperiHome

Post by waaren »

MikeF wrote: Saturday 05 January 2019 17:30 Many thanks for this. I'm not sure what you mean by creating a virtual setpoint device? I currently have a setpoint device (called 'Setpoint') in the Utilities tab, and when this is changed in the Domoticz GUI, or in ImperiHome, the lua script calls the python script, which then changes the real Hive thermostat by invoking the Hive JSON API.
Sorry for being unclear. What I meant is that if the delay in calling the python code is too long for the domoticz initiated setpoint change, it would be possible to change the behavior of the script.
That would require an additional virtual setpoint. The modified script would look at this device and trigger the Python code instantly and update the ImperiHome controlled setpoint at (allmost) the same time. This new setpoint is not to be controlled by InitelliHome. If you want / need that I need to know the type and subtype of your current Setpoint device.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: dzVents multiple setpoint updates through ImperiHome

Post by MikeF »

OK, I understand. I think that the first option you proposed will be acceptable - after all, when the Hive system initiates changes (schedule / temperature reaching setpoint, etc.), then it can take up to 1 minute before my script reads the updated values. I'll update my script with your changes.
Many thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest