Read switch state from json/domoticz
Moderators: grovkillen, Stuntteam, TD-er
Read switch state from json/domoticz
Hello,
I haven't found the answer to this question i have.
Is it possible to read out a switch state in domoticz with espeasy on a wemos, and have a GPIO switch accordingly ?
What i'm trying to achieve is to control the deep sleep of the Wemos D1 mini with a switch on domoticz.
Depending on the state of the switch in domoticz i want to change the state of a relay, that connects GPIO16 to GND or RST
This because i want to automate my solar lights in the garden.
During the day i have a solarpanel charge the battery of the wemos (which is in deep sleep Zzzzzz)
When it get's dark have domoticz activate a virtual switch. So the Wemos detects this when he wake's up (hourly e.g.) and it disables deepsleep and activate other relais that turns on the solar lights (replaces on/off switch of the solar light, the light still has its own battery)
When the switch in domoticz get's turned off, the relays of the lights changes, turning off the lights and also change relay for deep sleep, connectiong GPIO16 back to RST.
In my mind it would work great.
But i'm missing some knowledge of how to have the wemos detect the state of switch.
Thanks for the help for my strange project
I haven't found the answer to this question i have.
Is it possible to read out a switch state in domoticz with espeasy on a wemos, and have a GPIO switch accordingly ?
What i'm trying to achieve is to control the deep sleep of the Wemos D1 mini with a switch on domoticz.
Depending on the state of the switch in domoticz i want to change the state of a relay, that connects GPIO16 to GND or RST
This because i want to automate my solar lights in the garden.
During the day i have a solarpanel charge the battery of the wemos (which is in deep sleep Zzzzzz)
When it get's dark have domoticz activate a virtual switch. So the Wemos detects this when he wake's up (hourly e.g.) and it disables deepsleep and activate other relais that turns on the solar lights (replaces on/off switch of the solar light, the light still has its own battery)
When the switch in domoticz get's turned off, the relays of the lights changes, turning off the lights and also change relay for deep sleep, connectiong GPIO16 back to RST.
In my mind it would work great.
But i'm missing some knowledge of how to have the wemos detect the state of switch.
Thanks for the help for my strange project
Re: Read switch state from json/domoticz
I think you should rather invest 2,5€ for a lux-sensor on that garden esp und achieve desired function with rules. It wakes up every 72 min anyway. So measure the light value every time it wakes up. Decide in rules to continue sleeping or stay awake.
The other way could be a mqtt var with retain option enabled, but someone actually using mqtt should confirm that.
The other way could be a mqtt var with retain option enabled, but someone actually using mqtt should confirm that.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Read switch state from json/domoticz
I understand you want to retrieve the status of the virtual switch in Domoticz.
I have never seen an example of that and a lux sensor seems a simpler solution indeed.
Do you realize that in this setup it may take an hour between setting the switch and turning on the lights (depending on the sleeptime of the ESP)?
I have never seen an example of that and a lux sensor seems a simpler solution indeed.
Do you realize that in this setup it may take an hour between setting the switch and turning on the lights (depending on the sleeptime of the ESP)?
Re: Read switch state from json/domoticz
Yes, a lux sensor would be simpler. But i don't need that. If i want the Solar lights to turn on when dark, and off when light (or battery empty) i don't need to change anything at all. The lights do that by themselves.a lux sensor seems a simpler solution indeed.
But i thought, "Let's control it". And have an ESP switch the solar lights on/off switch on or off. So the battery get's charged but they don't turn on every night.
This also means, hopefully, they last longer when i do want them turned on.
And yes, it might take an hour to have the solar lights turned on, but that depends on the rest of the scripts
For example, i want to have the solar lights only turned on on Saturday and Sunday, between 19:00 and 00:00.
I don't know how to achieve that with a lux sensor only, on an ESP.
And i don't want to have the ESP run all day too. It's going to be battery powered and solar charged too.
But thanks for the replies and thoughts so far:)
Re: Read switch state from json/domoticz
Well, then a MQTT retained message may be the way to go.
A nice explanation is here http://www.hivemq.com/blog/mqtt-essenti ... d-messages
You will need a script on Domoticz side to publish the (retained) message and
a MQTT import device on ESPEasy to retrieve it after wakeup.
A nice explanation is here http://www.hivemq.com/blog/mqtt-essenti ... d-messages
You will need a script on Domoticz side to publish the (retained) message and
a MQTT import device on ESPEasy to retrieve it after wakeup.
Re: Read switch state from json/domoticz
Define user variable in Domoticz and set it to 0.
When your ESPEasy wakeups, set this variable to 1
( Through JSON API call - /json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE )
In Domoticz make script, which when this variable is changed, sends command with your Domoticz switch state to your ESPEasy and sets user variable to 0 again for next call.
In your ESPEasy Rule event set gpio according value received in cmd from Domoticz,
When your ESPEasy wakeups, set this variable to 1
( Through JSON API call - /json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE )
In Domoticz make script, which when this variable is changed, sends command with your Domoticz switch state to your ESPEasy and sets user variable to 0 again for next call.
In your ESPEasy Rule event set gpio according value received in cmd from Domoticz,
Re: Read switch state from json/domoticz
Interesting thoughts.kimot wrote: ↑12 Feb 2018, 22:45 Define user variable in Domoticz and set it to 0.
When your ESPEasy wakeups, set this variable to 1
( Through JSON API call - /json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE )
In Domoticz make script, which when this variable is changed, sends command with your Domoticz switch state to your ESPEasy and sets user variable to 0 again for next call.
In your ESPEasy Rule event set gpio according value received in cmd from Domoticz,
I'll go try that.
Thanks.
Re: Read switch state from json/domoticz
Hey,
It's been a while, but i wanted to let you know that i got this all figured out and wanted to share how i got this working.
(For someone else with carzy mind that thinks up such weird thing.)
The ESP send an on-boot message (on System#boot) to domoticz, with SendToHTTP, to change a variable to "1".
On sleep it sends a message with "on System#Sleep" to domoticz to change the same variable to "0".
On change of this variable to "1", domoticz checks if the dummy switch "ESP" is on or off.
(This switch "ESP, is on a timer, 45 min before the next switch. This because the ESP awake's every 30 min.)
If it is "on" it switches another dummy switch. This switch has on/off actions to switch on or off the relay on the ESP (control?cmd=GPIO,13,1)
The relay switches the GPIO16 pin (D0) to GND.
If D0 is connected to GND, the ESP stays on.
Then domoticz can trigger the 2nd relais, to turn on the solar lights. (control?cmd=GPIO,15,1)
This is on a timer in domoticz. It switches on 45 minutes after the "ESP" dummy switch.
At a set time the relay for the solar lights get's switched off again (control?cmd=GPIO,15,0), and 5 minutes later the switch that controls the first relais get's switched off (control?cmd=GPIO,13,0)
When this one get's switched off, it now connects D0 to RST.
This makes the ESP go to sleep mode within a few seconds.
Thanks for Kimot for pointing me into the right direction.
And the others too, ofcourse, for thinking along.
It's been a while, but i wanted to let you know that i got this all figured out and wanted to share how i got this working.
(For someone else with carzy mind that thinks up such weird thing.)
The ESP send an on-boot message (on System#boot) to domoticz, with SendToHTTP, to change a variable to "1".
On sleep it sends a message with "on System#Sleep" to domoticz to change the same variable to "0".
On change of this variable to "1", domoticz checks if the dummy switch "ESP" is on or off.
(This switch "ESP, is on a timer, 45 min before the next switch. This because the ESP awake's every 30 min.)
If it is "on" it switches another dummy switch. This switch has on/off actions to switch on or off the relay on the ESP (control?cmd=GPIO,13,1)
The relay switches the GPIO16 pin (D0) to GND.
If D0 is connected to GND, the ESP stays on.
Then domoticz can trigger the 2nd relais, to turn on the solar lights. (control?cmd=GPIO,15,1)
This is on a timer in domoticz. It switches on 45 minutes after the "ESP" dummy switch.
At a set time the relay for the solar lights get's switched off again (control?cmd=GPIO,15,0), and 5 minutes later the switch that controls the first relais get's switched off (control?cmd=GPIO,13,0)
When this one get's switched off, it now connects D0 to RST.
This makes the ESP go to sleep mode within a few seconds.
Thanks for Kimot for pointing me into the right direction.
And the others too, ofcourse, for thinking along.
Who is online
Users browsing this forum: No registered users and 0 guests