"watchdog" relay

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

"watchdog" relay

#1 Post by miralant » 06 Dec 2020, 15:15

Hi,

Currently I use espeasy on ESP01 to manage relay card. I want to create a rules who can switch off my relay after 20min for example whatever the state of the relay.

ex :
My domoticz call : http://192.168.1.23/control?cmd=gpio,0,1
>>timer is set ON at 20min.

At the end of the timer, the event set GPIO0 to 0

Thanks for your help.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#2 Post by TD-er » 06 Dec 2020, 16:03

There are several ways to do it (all requiring a fairly recent build)

By far the simplest one:
Change your command from "gpio" to "longpulse"
See: https://espeasy.readthedocs.io/en/lates ... =longpulse

Another option using rules:
First add monitoring to the pin, which does allow you to receive an event in case the pin state changes.
N.B. you also receive the new state as %eventvalue%, but you can also act on a specific state.
See: https://espeasy.readthedocs.io/en/lates ... ore-events

In the event handling this state change you can set a timer, which will generate an event which you can also act on in the rules to set the GPIO to 0.

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#3 Post by miralant » 07 Dec 2020, 09:05

TD-er wrote: 06 Dec 2020, 16:03 There are several ways to do it (all requiring a fairly recent build)

By far the simplest one:
Change your command from "gpio" to "longpulse"
See: https://espeasy.readthedocs.io/en/lates ... =longpulse

Another option using rules:
First add monitoring to the pin, which does allow you to receive an event in case the pin state changes.
N.B. you also receive the new state as %eventvalue%, but you can also act on a specific state.
See: https://espeasy.readthedocs.io/en/lates ... ore-events

In the event handling this state change you can set a timer, which will generate an event which you can also act on in the rules to set the GPIO to 0.
solution long pulse not impossible :) Just to be more clear :)

I use my esp to drive my boiler. domoticz is used to enslave esp to temperature. So I've a lua program who sends every minute 1 or 0 to drive ESP.

my need is simply to have a watch dog in case if my esp loose wifi or domoticz becomes crazy.

1. GPIO change state 0 to 1
2. launch 20 min timer
3. event end of timer => GPIO = 0

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#4 Post by TD-er » 07 Dec 2020, 09:12

Then you should go for the rules option.

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#5 Post by miralant » 11 Dec 2020, 19:31

ok, I think I inderstand but I'm a little bit lost.

1. GPIO change state 0 to 1

Code: Select all

How catch 0 to 1 change ?
timerSet,1,1200
2. launch 20 min timer
3. event end of timer => GPIO = 0

Code: Select all

on Rules#Timer=1 do
 GPIO,0,0
endon
tks

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#6 Post by TD-er » 11 Dec 2020, 19:55

See the documentation on the "monitor" command: https://espeasy.readthedocs.io/en/lates ... ore-events

Code: Select all

on System#Boot do
 Monitor GPIO,15
endon

 on GPIO#15=0 do
  if [Plugin#GPIO#Pinstate#13]=0
   // do something
  endif
 endon

 on GPIO#15=1 do
  if [Plugin#GPIO#Pinstate#13]=1
   // do something
  endif
 endon
 
This is the example from the docs, showing how to activate monitoring GPIO 15 and also if it changes, how to check the state of another GPIO (13) and act on it.

See here for documentation on "timerset": https://espeasy.readthedocs.io/en/lates ... rset#timer

So this can be combined into something like this:

Code: Select all

on System#Boot do
 Monitor GPIO,15
endon

on GPIO#0=1 do
  timerSet,1,20     // Set timer to 20 seconds
endon

On Rules#Timer=1 do
  GPIO,0,0
endon

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#7 Post by miralant » 13 Dec 2020, 19:09

Thanks, I've activate rules menu and try :

Code: Select all

on System#Boot do
 Monitor GPIO,0
endon

on GPIO#0=1 do
  timerSet,1,20     // Set timer to 20 seconds
endon

On Rules#Timer=1 do
  GPIO,0,0
endon
But nothing happens after 20s switching ON GPIO0 and nothing in logs (only "694884 : WD : Uptime 11 ConnectFailures 0 FreeMem 28544")

I'm on
Build: 120
Core Version: 2_3_0

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#8 Post by TD-er » 13 Dec 2020, 19:30

Ah build 120, that one is ancient and does not support "monitor" and likely other calls may also not yet work as they do now.

Can you please try a build which isn't like 3 years old?
See: https://github.com/letscontrolit/ESPEasy/releases

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#9 Post by miralant » 14 Dec 2020, 08:47

of course.

Is there a specific build for Puya version ? I remember that it was a specific for R120.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#10 Post by TD-er » 14 Dec 2020, 09:12

All builds should be able to handle Puya chips as it has been integrated in the esp8266/Arduino core since 2.5.x

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#11 Post by miralant » 16 Dec 2020, 19:43

I've update firmware to

Code: Select all

Build:⋄	20111 - Mega
System Libraries:⋄	ESP82xx Core 2843a5ac, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support
Git Build:⋄	
Plugin Count:⋄	46 [Normal]
Build Origin:	Travis
Build Time:⋄	Nov 30 2020 00:37:49
Binary Filename:⋄	ESP_Easy_mega_20201130_normal_ESP8266_1M
Build Platform:⋄	Linux-4.19.104-microsoft-standard-x86_64-with-glibc2.29
Git HEAD:⋄	mega-20201130_f4f960c

see logs bellow :

Code: Select all

890624: HTTP: gpio,0,0
890626: GPIO : port#0: set to 0
895338: HTTP: gpio,0,1
895340: GPIO : port#0: set to 1
903763: WD : Uptime 15 ConnectFailures 0 FreeMem 20728 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
928620: EVENT: Clock#Time=Thu,00:16
933753: WD : Uptime 16 ConnectFailures 0 FreeMem 24080 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
nothing happens after switching On GPIO0 :(

I've some strange connection failures but I can connect to it...

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#12 Post by miralant » 23 Dec 2020, 20:40

I apologies :) It works !!

So, I've try to add a return status to domoticz by calling API.

Code: Select all

SendToHTTP domoticz,8080,/json.htm?type=command[b]&para[/b]m=switchlight&idx=88&switchcmd=On
>>

Code: Select all

12584300: ACT : SendToHTTP domoticz,8080,/json.htm?type=command[b]¶[/b]m=switchlight&idx=88&switchcmd=On
but something goes wrong, &param is not correctly sends to http.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: "watchdog" relay

#13 Post by Ath » 23 Dec 2020, 20:59

miralant wrote: 23 Dec 2020, 20:40

Code: Select all

12584300: ACT : SendToHTTP domoticz,8080,/json.htm?type=command[b]¶[/b]m=switchlight&idx=88&switchcmd=On
but something goes wrong, &param is not correctly sends to http.
If you got this log from the web-interface: Nothing is going wrong, that's just the web-log page doing its 'thing' replacing &para with a paragraph sign, that's a known 'feature'.

Why not send the state to Domoticz using a Controller? Way easier and less error-prone. For a simple one-way status update, Domoticz HTTP is fine.

From an older message:
miralant wrote:

Code: Select all

WD : Uptime 16 ConnectFailures 0 FreeMem 24080 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
...
I've some strange connection failures but I can connect to it...
It says: Uptime 16 (minutes), Connection failures: 0 ...

Again, nothing to worry about ;)
/Ton (PayPal.me)

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#14 Post by miralant » 23 Dec 2020, 21:06

Ath wrote: 23 Dec 2020, 20:59
miralant wrote: 23 Dec 2020, 20:40

Code: Select all

12584300: ACT : SendToHTTP domoticz,8080,/json.htm?type=command[b]¶[/b]m=switchlight&idx=88&switchcmd=On
but something goes wrong, &param is not correctly sends to http.
If you got this log from the web-interface: Nothing is going wrong, that's just the web-log page doing its 'thing' replacing &para with a paragraph sign, that's a known 'feature'.

Why not send the state to Domoticz using
Sure but I've a specific need. That's why I want to use API. So if it's not an issue, I've to investigate on my domoticz to understand why it does not work.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#15 Post by TD-er » 23 Dec 2020, 21:13

miralant wrote: 23 Dec 2020, 20:40 I apologies :) It works !!

So, I've try to add a return status to domoticz by calling API.

Code: Select all

SendToHTTP domoticz,8080,/json.htm?type=command[b]&para[/b]m=switchlight&idx=88&switchcmd=On
>>

Code: Select all

12584300: ACT : SendToHTTP domoticz,8080,/json.htm?type=command[b]¶[/b]m=switchlight&idx=88&switchcmd=On
but something goes wrong, &param is not correctly sends to http.
You actually send the url with the forum bold tags?

Here without the bold tags:

Code: Select all

SendToHTTP domoticz,8080,/json.htm?type=command&param=switchlight&idx=88&switchcmd=On

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#16 Post by miralant » 23 Dec 2020, 21:15

TD-er wrote: 23 Dec 2020, 21:13
miralant wrote: 23 Dec 2020, 20:40 I apologies :) It works !!

So, I've try to add a return status to domoticz by calling API.

Code: Select all

SendToHTTP domoticz,8080,/json.htm?type=command[b]&para[/b]m=switchlight&idx=88&switchcmd=On
>>

Code: Select all

12584300: ACT : SendToHTTP domoticz,8080,/json.htm?type=command[b]¶[/b]m=switchlight&idx=88&switchcmd=On
but something goes wrong, &param is not correctly sends to http.
You actually send the url with the forum bold tags?

Here without the bold tags:

Code: Select all

SendToHTTP domoticz,8080,/json.htm?type=command&param=switchlight&idx=88&switchcmd=On
No :) I've use bold to focus on the issue between code and log

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#17 Post by miralant » 24 Dec 2020, 12:04

let me gave us more information.

when I launch :

Code: Select all

http://domoticz:8080/json.htm?type=command&param=switchlight&idx=88&switchcmd=On
> my switch is set to ON

on the rules :

Code: Select all

On Rules#Timer=1 do
GPIO,0,0
SendToHTTP domoticz,8080,/json.htm?type=command&param=switchlight&idx=88&switchcmd=On
endon
the log resultin :

Code: Select all

68307215: HTTP: gpio,0,1
68307217: GPIO : port#0: set to 1
68307225: EVENT: GPIO#0=1
68307231: ACT : timerSet,1,5
68312233: EVENT: Rules#Timer=1,1
68312241: ACT : GPIO,0,0
68312242: GPIO : port#0: set to 0
68312245: ACT : SendToHTTP domoticz,8080,/json.htm?type=command¶m=switchlight&idx=88&switchcmd=On
68312319: EVENT: GPIO#0=0
Event is fired but switch is not set to ON

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: "watchdog" relay

#18 Post by Ath » 24 Dec 2020, 12:36

Does your Domoticz require a username/password to be able to get access? Most likely it does, and your browser is quietly providing those to Domoticz, so there it will work.

When sending commands to Domoticz from other sources, like ESPEasy, the username & password need to be supplied (base64 encoded) as arguments in the url:

Code: Select all

SendToHTTP,domoticz,8080,/json.htm?username=BASE64USERNAME&password=BASE64PASSWORD&type=command&param=switchlight&idx=%eventvalue1%&switchcmd=On
AFAICS, the base64 has to include padding.
/Ton (PayPal.me)

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#19 Post by miralant » 24 Dec 2020, 13:11

Yes, I've credentials to access to front of Domoticz. But to access to json, I'm not sure. I remember that I've sh where I push credentials in url (for IFTTT). I dont know why but I was thinking that from local (192.168.x.x) it will need no credentials :oops: .

Just a question, concerning credentials.

In some example, Username and passeword are sent in before URL :

Code: Select all

http://username:pwd@domoticz:8080/json.htm?type=command&param=switchlight&idx=88&switchcmd=On&level=0&passcode=
and in other case, like you're exemple with pwd and username in base 64 directly to json.

Code: Select all

http://username:pwd@domoticz:8080/json.htm?username=BASE64USERNAME&password=BASE64PASSWORD&type=command&param=switchlight&idx=88&switchcmd=On
It's the same results ?

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: "watchdog" relay

#20 Post by Ath » 24 Dec 2020, 13:28

Haven't tried to authenticate with username:pwd@domoticz but I'd assume that's not directly supported by ESPEasy, so the &username= and &password= arguments in the url is easy to apply, just use Notepad++ with the MIME Tools plugin (installed by default, I think, not sure) or an on-line service will provide you with something useful, f.e. admin will translate to YWRtaW4= so you use that result (with the = padding included) in the url.
/Ton (PayPal.me)

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#21 Post by miralant » 27 Dec 2020, 08:26

works like a charm by pusching credentials to json.

Thanks for your help

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#22 Post by miralant » 06 Feb 2021, 19:06

Hi,

Just to add new technology to my domoticz and acquire new skills :), I've mount MQTT server (mosquitto) and connects my espeasy to domoticz with MQTT.

It works like a charm but i've a question :) My rules is like that :

Code: Select all

on System#Boot do
 Monitor GPIO,0
endon

on GPIO#0=1 do
  timerSet,1,5     // Set timer to 5 seconds
endon

On Rules#Timer=1 do
GPIO,0,0
SendToHTTP domoticz,8080,/json.htm?username=xxx&password=yyyy&type=command&param=switchlight&idx=88&switchcmd=Off&level=0&passcode=
endon
as you can see, at the end of the timer, the return state is made with json request. Sure it works but how can I do the same with MQTT to be consistent ?

Thanks

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: "watchdog" relay

#23 Post by Ath » 06 Feb 2021, 19:17

This is where the Domoticz MQTT Controller comes in ;)

- Configure the Domoticz MQTT Controller using the correct username/password
- Lookup in Domoticz what the matching Dummy device's IDX is
- In ESPEasy set up a Switch device using GPIO-0.
- Enable the Controller on the Device Configuration for the switch using the IDX obtained before

That should report the status to Domoticz, using the Domoticz/in topic, no need to report status every time, it will be sent when status changes (both on and off).
/Ton (PayPal.me)

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#24 Post by miralant » 06 Feb 2021, 19:27

That's exactly what I did.
When I click on the dummy device in domoticz (Switch), the GPio is set to 1 (and Relay click :mrgreen: ).
But when the timer sets GPio to 0, in domoticz the switch does not change state.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: "watchdog" relay

#25 Post by Ath » 06 Feb 2021, 21:38

miralant wrote: 06 Feb 2021, 19:27 But when the timer sets GPio to 0, in domoticz the switch does not change state.
That's exactly what the Controller selection (and IDX) on the Device configuration page is for... quite surprising you can't get it working, as it is exactly how I set up my Sonoff S20's to make them work reliably. And they react to and show their state however I change the relay GPIO state.
For controlling a GPIO pin on an ESP, I use the Domoticz MQTT Helper plugin to set the relay in the correct state. (That also takes an IDX, and expects the Domoticz MQTT Controller active.)
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: "watchdog" relay

#26 Post by TD-er » 07 Feb 2021, 00:41

See here for more info on the Domoticz Helper plugin: https://espeasy.readthedocs.io/en/lates ... #p029-page

miralant
Normal user
Posts: 40
Joined: 06 Apr 2018, 08:05

Re: "watchdog" relay

#27 Post by miralant » 07 Feb 2021, 16:47

Thanks for your help.

I only had created the Domoticz MQTT Helper not the Switch input. That's why return stat does not work I think.

really thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests