Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change relay status if MQTT disconnects #602

Closed
gokalpakgul opened this issue Feb 24, 2018 · 8 comments
Closed

Change relay status if MQTT disconnects #602

gokalpakgul opened this issue Feb 24, 2018 · 8 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request mqtt relay

Comments

@gokalpakgul
Copy link

Dear All

With Espurna 1.12.3 firmware is it possible that relay switches to OFF mode if the MQTT connection is broken for the safety reason? I saw MQTT retain option but no MQTT OFF option. Is there a plan to implement such a function?

Thks for your answers in advance

Gokalp

@xoseperez xoseperez changed the title Espurna 1.12.3 Change relay status if MQTT disconnects Feb 26, 2018
@xoseperez
Copy link
Owner

I have never thought about it. If the MQTT disconnects it should reconnect as soon as the WiFi connection is restored or the broker available again... what kind of safety reasons are you thinking about?

@gokalpakgul
Copy link
Author

Assume that espurna is ON by the broker and after some time connection is broken. Because of wireless connection this can happen if wireless signal is weak. So we have the issue that Espurna stays ON. So if there is a setting in web server for MQTT such that if the connection is broken e.g. for 5 minutes if Espurna should switch to OFF this issue can be solved.

@mcspr
Copy link
Collaborator

mcspr commented Mar 2, 2018

@gokalpakgul did you consider unconventionally using pulse mode? For example, set it to 5 minutes, Normally OFF and just periodically send 1 to sonoff/relay/0/set Pulse timer will restart every time it receives mqtt message and will turn off when it misses one.

@torwag
Copy link

torwag commented May 6, 2018

That the timer will reset is a good start. I was looking exactly for the same functionality. Some application require that the relay switch off as a safety feature... e.g. if the broker crashes or wifi is borked, a gardening watering pump, which is suppose to run for 30 min a day, would run endless possibly creating larger damage to garden and buildings. Thus, we need a safety feature. If there is no connection and no response from the server side for e.g. 5 min, the pump should switch off.

@mcspr
Copy link
Collaborator

mcspr commented May 7, 2018

@torwag For device-only option there's also scheduling function that uses network time to turn on / off relay - see Scheduler on web interface.
i.e. you can schedule it for specific time of day and set pulse timer to 30 minutes. But there are also couple of issues with this approach:

  • it will not trigger if the time is missed. for example, ntp clock borked and changed from 19:01 to 19:03 when schedule is set to 19:02 - nothing happens.
  • pulse is bound to device runtime, thus rebooting the device when timer got 15 of 30 minutes left and restoring last relay status (espurna can remember relay state between reboots, but it will still be temporary off ~1sec) does not restore the timer - it will run for 30 minutes again.

If network is fairly stable, short pulse time and periodic keep-alive using relay/set does the thing. You can have 90 second pulse and 60 seconds interval between sending /set - 29 times and let the pulse timer run out to turn the relay off.

Edit: there's also #653

@ghost
Copy link

ghost commented May 7, 2018

@torwag I have the same need as you have. It seems solved using pulse mode normaly off with a timer on 30minutes and boot mode always off

On the last release (espurna-1.12.6-itead-sonoff-4ch-pro.bin) there are also a On MQTT disconnect option but this option is not kept after reboot.

@torwag
Copy link

torwag commented May 7, 2018

Thanks for the comments. I use the same method as @fpalinf ... pulse mode with boot mode off.
As for the timer... it really should not miss a scheduled time... looks to me like a == has to be replaced by a >= together with the introduction of a small simple state-machine.

I will further investigate and see if it works as I need it to work. Thanks again for this great project.

@xoseperez xoseperez added this to the 1.12.7 milestone May 8, 2018
@xoseperez
Copy link
Owner

See also #845.

@xoseperez xoseperez modified the milestones: 1.12.7, 1.13.0 Jun 4, 2018
@xoseperez xoseperez added the duplicate This issue or pull request already exists label Jun 4, 2018
@xoseperez xoseperez removed this from the 1.13.0 milestone Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request mqtt relay
Projects
None yet
Development

No branches or pull requests

4 participants