I’m trying to create a light entity working with a bistable relay. Right now I connect the relay with an esp32 on 2 GPIOs one for trigger (button) and one for status (binary sensor). This is the wiring:
Thank you zoogara Daryl,
but your code will just re trigger the button.
A bistable relay, each time you press the button its changing the state. This is why I need the binary sensor to read the state. I have wired buttons, and I have Home assistant buttons. So in my Home assistant UI , the entity looks like this:
On Mushroom UI
type: custom:mushroom-template-card
primary: Baie mare
secondary: '{{states(''sensor.baie_mare_temperature'')}}°C'
icon: mdi:bathtub
entity: button.modul_lumini_1_lumina_baie_mare
icon_color: >-
{% if is_state('binary_sensor.modul_lumini_1_status_lumina_baie_mare', 'on')
%}
amber
{% endif %}
tap_action:
action: navigate
navigation_path: baie-mare
hold_action:
action: toggle
In a few words, I have a local switch (button), which is not displayed on the FE and is triggering the GPIO 21, which is going HIGH for 40ms and then LOW. This is enough to change the state of the latching (bistable) relay.
To reflect this on FE, I have a second switch (Template Switch), which is getting the state from binary sensor (Relay state), and is triggering “button” accordingly. Also if the relay is triggered externally, so the GPIO 25 is going HIGH or LOW, the the Template Switch change the state also.
Thank you for pointing out, Justin.
My decision to use bistable relay, is to have a system that will work even with a failure in the automation part, so I can switch my lights on and off from a wired switch.
From the description of this module, I see is accepting only 3-27V and 1.5A. I need to power 220V AC lights. Also, a bistable relay costs less than this module.