Feature request/suggestion: Update state of dummy switch via JSON
Moderators: leecollings, remb0
-
- 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
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
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.
-
- 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
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...
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
-
- 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
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
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
-
- 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
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.
-
- 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
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
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
-
- 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
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
script.
BR Søren
Sent using Tapatalk
-
- 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
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.I hope this makes sense
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.
-
- 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
Second thought. Have you ever tried the LUA command:
Based on the Json command described here: https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_on
Code: Select all
commandArray['UpdateDevice'] = 'idx|0|On'
commandArray['UpdateDevice'] = 'idx|0|Off'
Debian buster on NUC and three RPi with buster.
-
- 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
Thanks for your suggestion. After reading the thread you link to, I'm unsure if that would work in my scenario.Number8 wrote: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.I hope this makes sense
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
I have 70 dummy devices I would have to make this workaround on individually.
Br Søren
-
- 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
I'm using /json.htm?type=command¶m=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.Number8 wrote:Second thought. Have you ever tried the LUA command:Based on the Json command described here: https://www.domoticz.com/wiki/Domoticz_ ... Fswitch_onCode: Select all
commandArray['UpdateDevice'] = 'idx|0|On' commandArray['UpdateDevice'] = 'idx|0|Off'
I have also been trying with
/json.htm?type=command¶m=udevice&idx=20&nvalue=0&svalue=Off
/json.htm?type=command¶m=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
-
- 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
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.
-
- 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
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
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
-
- 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
The json code to update a variable is the following:
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
Code: Select all
/json.htm?type=command¶m=updateuservariable&idx=idx&vname=uservariablename&vtype=uservariabletype
&vvalue=uservariablevalue
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.
-
- 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
Thank you.. I will try it out and let you know if that will work
BR Søren
BR Søren
-
- 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
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.
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.
-
- 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
Excerpt of the wiki:
Wiki reference https://www.domoticz.com/wiki/Events
It is indeed cumbersome, but it is nice if it can do the trick
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.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.
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.
-
- 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
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
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
-
- 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
I'm a bit in a rush now, I'll answer to you this week-end
You're welcomePs. Thanks for your help, its much appreciated
Debian buster on NUC and three RPi with buster.
-
- 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
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
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.
-
- 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
Thanks. Excited to see how this works out
Who is online
Users browsing this forum: No registered users and 0 guests