Feature request/suggestion: Update state of dummy switch via JSON

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Hi,

A feature that would be very welcome is the ability to update the state of a dummy switch without triggering an event via JSON.

I'm having issues with looping.

For example. When I turn on the light in a room using the physical wall switch the new state is send to a dummy switch in Domoticz via JSON and when the dummy switch change state/turns on it tries to turn on the light one more time.

Thanks.

BR Søren
Last edited by SoerenBM on Thursday 26 May 2016 21:46, edited 1 time in total.
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by woody4165 »

How can you update the dummy device if you turn on a switch manually?
I have a wifi switch from Orvibo, model S20, and I found here on the forum someone that created a script that have to be in crontab that make a request to the switch and update accordingly the dummy switch if was manually switched.
Maybe it's the only way...
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Hi,

I have have another system (called IHC Captain) that monitors my electrical installation (called IHC Controller) and IHC Captain send updates dummy switches in Domoticz via JSON.

You can read about my setup in this post:
viewtopic.php?f=23&t=11782&p=84656

BR Søren
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

Is the physical switch known by Domoticz? In other words is it linked to Domoticz using any protocol that is supported (X10, Zwave, etc.)
Debian buster on NUC and three RPi with buster.
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

No, I only have dummy devices in Domoticz. I use Domoticz as master controller.

Domoticz are not able to communicate with my IHC Controlle that is why I use other systems(middleware) to make the connection to/from Domoticz.

I have played around with sub/slave devices but without success.

My current workaround are lua script that block pushes within 2 secs. This is however not flawless. So am looking for a permanent fix.

When a physical switch is pushed the light turns on > one middleware system sees this change and calls JSON API to turn on the switch in Domoticz.

If this call only would change the state of the switch in Domoticz all would be good. But Domoticz triggers an event by the switch being turned on. Then a lua script is called with a curl for rest api in openHAB hence the loop. OpenHAB has a binding for my type of system. Without the rest call to openhab I would not be able to turn a light on from Domoticz.

I hope this makes sense.


BR Søren

Sent using Tapatalk
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

That is my reason for this feature request. Being able to only update stat of a dummy switch via JSON without triggering an event that executes a lua
script.


BR Søren

Sent using Tapatalk
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

I hope this makes sense
indeed it does make sense. As a matter of fact I was curious to see if you could use the sub/slave function, which in your case, I agree, is pointless since the physical switch is unknow to Domoticz.
As a last resort you could update Domoticz DB directly (not very clean but workable). Have a look in the middle of this post: viewtopic.php?f=31&t=9933
Debian buster on NUC and three RPi with buster.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

Second thought. Have you ever tried the LUA command:

Code: Select all

commandArray['UpdateDevice'] = 'idx|0|On'
commandArray['UpdateDevice'] = 'idx|0|Off'
Based on the Json command described here: https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_on
Debian buster on NUC and three RPi with buster.
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Frature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Number8 wrote:
I hope this makes sense
indeed it does make sense. As a matter of fact I was curious to see if you could use the sub/slave function, which in your case, I agree, is pointless since the physical switch is unknow to Domoticz.
As a last resort you could update Domoticz DB directly (not very clean but workable). Have a look in the middle of this post: viewtopic.php?f=31&t=9933
Thanks for your suggestion. After reading the thread you link to, I'm unsure if that would work in my scenario.

I have 70 dummy devices I would have to make this workaround on individually.

Br Søren
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Number8 wrote:Second thought. Have you ever tried the LUA command:

Code: Select all

commandArray['UpdateDevice'] = 'idx|0|On'
commandArray['UpdateDevice'] = 'idx|0|Off'
Based on the Json command described here: https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_on
I'm using /json.htm?type=command&param=switchlight&idx=99&switchcmd=On and Off to update the state in Domoticz when when a light or socket are turned on using the physical wall switch.

I have also been trying with
/json.htm?type=command&param=udevice&idx=20&nvalue=0&svalue=Off
/json.htm?type=command&param=udevice&idx=20&nvalue=1&svalue=On

Both execute the script resulting the light getting turned on and off. So in my scenario there are no difference to the two commands.

BR Søren
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

the Json command has been given for reference only in order to describe what are the parameters of commandArray['UpdateDevice'] = 'idx|0|On' which updates the status only. If this works for you, so may be you could have a json command updating a Domoticz variable that would trigger the execution of a lua script.
Debian buster on NUC and three RPi with buster.
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Ahhh... I see. I was under the impression that using udevice in Json and using commandArray['UpdateDevice'] was the same thing.

However I'm unsure how I would by updating a variable trigger a script. That I have not done before.

But nonetheless I could set up a test switch device and see it it will work.


BR Søren

Sent using Tapatalk
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

The json code to update a variable is the following:

Code: Select all

/json.htm?type=command&param=updateuservariable&idx=idx&vname=uservariablename&vtype=uservariabletype
&vvalue=uservariablevalue
The wiki gives all the information you may need
https://www.domoticz.com/wiki/Domoticz_ ... g_variable
I'm pretty sure this could be your workaround until the json command is available
Debian buster on NUC and three RPi with buster.
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Thank you.. I will try it out and let you know if that will work :)

BR Søren
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

It’s kind of a cumbersome workaround but it _is_ working.

I only see two quarks

In the log event system is triggered three times in a row, that I find strange. Happens when the user variable is updated:
2016-05-27 12:03:34.927 EventSystem: Script event triggered: Garage_Loftlampe_NY
2016-05-27 12:03:35.087 EventSystem: Script event triggered: Garage_Loftlampe_NY
2016-05-27 12:03:35.247 EventSystem: Script event triggered: Garage_Loftlampe_NY

Next, when turning on or off the switch in Domoticz it usually shows the new state right immediately (ie. switch turned on the lamp lights up), now it waits for the user variable to be updated so it takes 10 secs for the GUI to refresh.

The physical light is turned on right away.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

Excerpt of the wiki:
In device scripts, *always* do a check on the state of the changed device first. The device scripts are triggered fairly often, especially when you have a lot of thermometers and other measurement devices. If you just set the commandArray without any conditions, the script always just execute those commands at every device change, and those changes will trigger the scripts again and again resulting in a loop.
Make sure in the LUA script you check the devicechanges status and make sure as well to test the user variable and the dummy switch current state in order to avoid multiple sending.
Wiki reference https://www.domoticz.com/wiki/Events
It is indeed cumbersome, but it is nice if it can do the trick
Debian buster on NUC and three RPi with buster.
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Yes, I actually have read that phrase several times going through the Wiki.

How would I do these check - of switch state and user variable. Can you give som examples?

Going through the Wiki and forum, I haven't seen any examples of how you would do those checks.

Perhaps this is basic knowledge but I'm very new in coding/scripting.

BR Søren

Ps. Thanks for your help, its much appreciated :D
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

I'm a bit in a rush now, I'll answer to you this week-end
Ps. Thanks for your help, its much appreciated
You're welcome :)
Debian buster on NUC and three RPi with buster.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by Number8 »

Here is the code from which I guess you may build your own solution. It has been tested.
You should remove, or comment the print command when you are happy with your script
When you develop in LUA, your two best friends are the Domoticz log and the print command that helps you to see what is going on
Good luck

Code: Select all

-- create a uservariable fakeState
-- create a dummy switch fake
-- If the fake switch is set on or off, the uservariable will be updated accordingly
-- If the user variable fakeState is set externally, the state of fake will be updated accordingly

fakeIDX='246'

commandArray = {}
if devicechanged['fake'] == 'On' then
	commandArray['Variable:fakeState'] = '1'
	print ('Variable fakeState updated')
elseif devicechanged['fake'] == 'Off' then
	commandArray['Variable:fakeState'] = '0'
	print ('Variable fakeState updated')
elseif uservariables['fakeState'] == 0 and otherdevices['fake'] == 'On' then 
	commandArray['UpdateDevice'] = fakeIDX..'|0|0'
	print ('fakeState = 0 and fake is On')
	print ('fake has been updated to Off')
elseif uservariables['fakeState'] == 1 and otherdevices['fake'] == 'Off' then 
	commandArray['UpdateDevice'] = fakeIDX..'|1|0'
	print ('fakeState = 1 and fake is Off')
	print ('fake has been updated to On')

else 

--print ('did nothing')

end
Debian buster on NUC and three RPi with buster.
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Feature request/suggestion: Update state of dummy switch via JSON

Post by SoerenBM »

Thanks. Excited to see how this works out :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests