Set GPIO to the status of a binary helper?

Hi Folks,
I’m kinda lost, maybe someone can pint me in direction:

  • I have multiple water leak sensors on multiple D1minis (one each)
binary_sensor: 
- platform: gpio
    pin: D3
    name: Leak
  • each D1 has also a buzzer
switch:
  - platform: gpio
    pin: D4
    name: "Buzzer"
  • each D1 also has push button to eventually stop the buzzer
- platform: gpio
    pin:
      number: D7
      inverted: true
      mode:
        input: true
        pullup: true
    name: "Reset Button"
    filters:
#      - delayed_on: 10ms
      - delayed_off: 10ms

I want all buzzers to go off if one leak sensor goes off
I want all buzzers to stop if I press any button for >3sec

Idea: Use a helper as “global variable”

What’s missing: I’d like to avoid maintaining automation with naming each single sensor and buzzer.
e.g.

  • create an automation to set a water alarm helper to TRUE if [list of leak sensors] activates
  • Create an automation to set the [list of buzzers] to buzzers to true if helper activates
  • Create an automation to set the helper to FALSE if [list of buttons] is pressed for >3sec

Can I avoid automation and set the helper to true from the D1
Can I make the D1 to simply subscribe to the helper and mirror it’s status to a GPIO (the buzzer)?

Thx folks! Any thought much appreciated!

Hi Henrik!

I can think of a few ways to make this happen. One way could be to use the Event action and have Home Assistant listen to this event in an automation.

As an example: I have a single automation that covers the auto-light turning on from all my presence sensors. Each sensor sends an event with the entity_id of the light and HA uses this to turn on the correct light.

In ESPHome:

...
on_turn_on:
  - homeassistant.event:
      event: esphome.auto_light
      data:
        entity_id: 'light.bedroom_light'
        state: 'on'
...

And in HA:

trigger:
  - platform: event
    event_type: esphome.auto_light
    event_data:
      state: "on"
condition: []
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: "{{ trigger.event.data.entity_id }}"
mode: single

You can also import the helper into each node and act when it get set to true.

1 Like

Thanks zenzay42!

I made it to react on the helper and switch on buzzers:

- platform: homeassistant
    id: wasser_alarm
    entity_id: input_boolean.wasser_alarm
    internal: true
    on_state:
      then:
        - if:
            condition:
              binary_sensor.is_on: wasser_alarm
            then:
              - switch.turn_on: buzzer
            else:
              - switch.turn_off: buzzer

switch:
  - platform: gpio
    pin: D4
    name: "Buzzer"
    id: buzzer

I’ll be checking out the event mechanism for the other direction, that is: send water alarm state and reset.

thx a lot!

Just in case some one is following this:

api:

binary_sensor:
 #
 # Wasser Sensor
 #
 - platform: gpio
   pin: D3
   name: "Wasser Sensor"
   filters:
     - delayed_on: 1500ms
     - delayed_off: 10ms
     - invert
   on_press: 
     then:
       - homeassistant.event:
             event: esphome.wasser_alarm
             data:
               entity_id: 'wasser_alarm'
               state: 'on'
       - logger.log: "Wasser alarm triggered"

 #
 # Reset button
 #
 - platform: gpio
   pin:
     number: D7
     inverted: true
     mode:
       input: true
       pullup: true
   name: "Reset Button"
   filters:
     - delayed_on: 1500ms
     - delayed_off: 10ms
   on_press: 
     then:
       - homeassistant.event:
             event: esphome.wasser_alarm
             data:
               entity_id: 'reset_alarm'
               state: 'on'
       - logger.log: "Reset triggered"

Automation in HA

alias: Wasser alarm event handler
description: ""
trigger:
  - platform: event
    event_type:
      - esphome.wasser_alarm
    event_data:
      entity_id: wasser_alarm
condition: []
action:
  - service: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.wasser_alarm
mode: single

I want to mention here that I was not able to fulfill this requirement of not maintaining an entity list with the new event entity thingy, see discussion here:
https://community.home-assistant.io/t/triggering-ha-automation-by-esphome-event/736606