The configuration I provided does all that. It sends events in all these cases. You just need to set up your automations to listen for the right events. The events are esphome.switch_click, esphome.switch_double_click and esphome.switch_long_press. The data of the event will include which switch it is from and which button was used.
So, for example, you could listen to the esphome.switch_long_press event with data of:
device: switch-1
button: left
And your automation will only happen when the left button of switch-1 is long pressed.
Based on Jasper123 great script the events of the long_press, double etc can be placed in a automation. For me it was not clear how to trap these events but I finally understood his comments.
Here is screenshot of how it listen to these events.
I somehow prefer to code actions directly in ESPHOME setup rather than firing events to HA and then reacting over there, i.e.
- timing: #short
- ON for at most 1s
- OFF for at least 0.05s
then:
- if:
condition:
api.connected:
then:
- homeassistant.service:
service: light.toggle
data:
entity_id: light.table_lamp
else:
- http_request.post: "http://192.168.10.77/light/table_lamp/toggle"
btw,the condition is to go directly to Esphome device if HA is unavailable (fallback option, HA way reacts way faster)
Would it be possible to change Jaspers script (which is great) to use the single press to switch on a light through HA. But when HA is unreachable (I.e. server is offline, wifi is down) to fallback to the local relay?
I attempted asking for help a few times and deleted my posts, each time I thought I had it figured, I later got stuck. Iāll like to implement this condition into Jasperās config because Iām getting an error when I do. Iād like to have a fall back to toggle my zigbee hue light of HA goes down. Thanks.
I got XNDZās script implemented into Jaspersās and works great, the only downside is that the red ledās are connected to the relays. The double and long press dims and brightens my hue light, awesome. Thanks guys!
Iāll like to know how to power on the relay by default. When thereās an outage (which we experience here often) the M5 would start up being off at default. Iāll rather put this into ESPhome rather than HA automations. Someone please help me with this, thanks.