Page 1 of 1

Problem with activation device in group [solved]

Posted: Friday 23 June 2023 8:20
by desliem
As often recommended in the forum (example: emontnemery's last sentence), I have created a group with a single device "Garage" and a single activation device "Balcony". Both correspond to outside lights.

When the virtual balcony light is turned on in the Domoticz Web interface, the virtual garage light turns on and the actual balcony and garage lights turn on, just as expected. When the actual balcony light is turned on, the virtual balcony light turns on but both the real and virtual garage lights remain off. Seems strange to me, is that the expected behaviour?

Just to be clear, I would like to be able to turn the garage light on or off on its own without effect on the balcony light. But the garage light must follow the balcony light when the later is turned off or on. This is easy to do with a dzVents script which is how I used to do it. I created a new test group with two other switches just in case there was a script somewhere interfering with the first group.

More info:

Domoticz version: 2023.1

Both lights are connected to Wi-Fi switches running Tasmota. That means that the balcony light switch sends the following MQTT message when switched on.

Code: Select all

[domoticz/in] - {"idx":195,"nvalue":1,"svalue":"","Battery":100,"RSSI":7}

That's it, no other MQTT messages are transmitted and the garage light does not get turned on.

When the virtual balcony light is turned on in the Web interface or with an HTTP request,

Code: Select all

curl "http://192.168.1.22:8080/json.htm?type=command&param=switchlight&idx=195&switchcmd=On"
{
	"status" : "OK",
	"title" : "SwitchLight"
}
the following messages are transmitted.

Code: Select all

[domoticz/out] - {
	"Battery" : 255,
	"LastUpdate" : "2023-06-23 02:33:08",
	"RSSI" : 12,
	"description" : "",
	"dtype" : "Light/Switch",
	"hwid" : "2",
	"id" : "00014113",
	"idx" : 195,
	"name" : "Balcony",
	"nvalue" : 1,
	"stype" : "Switch",
	"svalue1" : "0",
	"switchType" : "On/Off",
	"unit" : 1
}

[domoticz/in] - {"idx":195,"nvalue":1,"svalue":"","Battery":100,"RSSI":7}

[domoticz/out] - {
	"LastUpdate" : "2023-06-23 02:33:08",
	"Name" : "test",
	"Status" : "On",
	"Timers" : "false",
	"Type" : "Group",
	"idx" : 17
}

[domoticz/out] - {
	"Battery" : 255,
	"LastUpdate" : "2023-06-23 02:33:08",
	"RSSI" : 12,
	"description" : "cesmart plug",
	"dtype" : "Light/Switch",
	"hwid" : "2",
	"id" : "000140A7",
	"idx" : 87,
	"name" : "Garage",
	"nvalue" : 1,
	"stype" : "Switch",
	"svalue1" : "1",
	"switchType" : "On/Off",
	"unit" : 1
}

Re: Problem with activation device in group

Posted: Friday 23 June 2023 23:53
by desliem
Been bitten by this before and corrected by waaren in 2020. Also should have read the post just before this one! "I learn fast if you repeat the lesson many many times".

The problem is that Tasmota sends an MQTT message that only updates the status of the virtual activation device.

One solution around this is to forget about using a group. Instead define a Tasmota rule in the balcony switch (idx 195) that publishes an explicit MQTT message for the virtual garage switch (idx 87) to turn the light on or off when the relay of the balcony switch is turned on or off. Here is the definition of the rule to be entered in the Web console.

Code: Select all

Rule1 ON Power1#state=1 DO publish domoticz/in {"command":"switchlight", "idx":87, "switchcmd":"On"} ENDON  ON Power1#state=0 DO publish domoticz/in {"command":"switchlight", "idx":87, "switchcmd":"Off"} ENDON
The rule has to be turned on.

Code: Select all

Rule1 1
However, this will only work after setting the "Prevent loop" setting of the MQTT hardware to "false". That can cause problems.

Consequently, going back to my initial solution with a dzVents script:

Code: Select all

--[[
    Balcony (idx 195) will also control Garage (idx 87)
    see: https://www.domoticz.com/forum/viewtopic.php?t=40484
]]

return 
{
	on = 
	{
		devices = 
		{
			195, 
	    },
	},
	
	logging = 
	{
        level = domoticz.LOG_ERROR, -- change to LOG_ERROR when script is fucntioning as expected
        marker = 'Balcony',
    },

	execute = function(dz, item)
		dz.log(item.name .. ' is now ' .. item.state , dz.LOG_DEBUG)
		if item.active then
		   dz.devices(87).switchOn()
		else
		   dz.devices(87).switchOff() 
	    end
	end
}
Works no matter if the MQTT hardware "Prevent loop" is set to "false" or "true".