itead / Sonoff_Devices_DIY_Tools

BSD 3-Clause "New" or "Revised" License
548 stars 168 forks source link

How to have the Mini R2 report a physical SPDT switch state change #114

Open hepcat72 opened 2 years ago

hepcat72 commented 2 years ago

I just implemented a polling strategy to keep my app's button state synced to the actual power state of the switch, but I don't like the polling strategy as a solution. It's too busy.

I would like to know if there's a way to make the mini R2 report state changes so that the power state of the switch in my home app accurately reflects the power state of the actual circuit.

Specifically, I would like to be able to set a webhook URL value in the R2 that it calls when the power state changes.

Ideally, you could specify whether the state change came from the SPDT switch or via webhook call.

Is this already possible and I just overlooked how to do it in the doc?

VTsuprov commented 2 years ago

I went through the ...Doc v2.pdf and have found nothing about it updated: In case of physical button push Sonoff publiches its status in the network. You can see it by calling something like avahi-browse -a

VTsuprov commented 2 years ago

For the Nodejs you can use this tool: https://www.npmjs.com/package/multicast-dns

hepcat72 commented 2 years ago

Hmmm, I don't have a push-button. I have an SPDT switch, as mentioned in the user manual.

The eWeLink app reports the state of that switch, because when I flip it, the state of the virtual button in the eWeLink app changes. I would just like to report that state update using DIY mode.

I already implemented a polling strategy to retrieve that state, but polling is a busy implementation - a lot of wasted cycles. It would be much more efficient if I could make the Mini R2 send state change events when they happen. That is what I'm inquiring about here. Is this possible with DIY mode or would I need to flash with tasmota to obtain that functionality?

hepcat72 commented 2 years ago

For example, if there was a webhook URL option in DIY mode that I could set that the Mini R2 could use to report state changes, that would be ideal. Let's call it "reporting_url". I would want to set it to something like http://mynode-red.local:1880/minir2-state-changes. When the state changes on the R2, it would call that URL and my node red instance could update the state of the button in the Home app.