Page 1 of 1
Feature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 14:53
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
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 15:05
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...
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 15:22
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
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 18:45
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.)
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 19:55
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
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 20:00
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
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 21:40
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 21:53
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
Re: Frature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 22:19
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Thursday 26 May 2016 22:29
by SoerenBM
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.
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 7:14
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.
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 7:55
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 8:23
by Number8
The json code to update a variable is the following:
Code: Select all
/json.htm?type=command¶m=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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 8:40
by SoerenBM
Thank you.. I will try it out and let you know if that will work
BR Søren
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 12:08
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.
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 13:57
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 14:16
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Friday 27 May 2016 15:22
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Saturday 28 May 2016 12:11
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
Re: Feature request/suggestion: Update state of dummy switch via JSON
Posted: Saturday 28 May 2016 20:33
by SoerenBM
Thanks. Excited to see how this works out