Relays following binary sensors in HA

Hello everyone,

I’m trying to work out how to switch relays using ESPHome to follow the status of binary sensors in Home Assistant but I’m not getting very far.

My intruder alarm system is integrated into HA and all my detectors are binary sensors (at least that’s what they report as in the Entities list).

I want to make a very low-tech display with lights to go by the front door to give a status of all the doors and windows.

Can anyone help get me started with associating sensors in HA directly with GPIO in ESPHome without having to manually create a load of triggers/automations etc?

A simple test, I added this in my ESPHome config and uploaded to the D1 Mini:

binary_sensor:
  - platform: homeassistant
    name: "Living Room PIR Front"
    entity_id: binary_sensor.living_room_pir_front

After it uploads, the log window displays this and if i trigger the physical sensor nothing happens (i expected the log window to scroll with the incoming messages from HA):

[09:34:18][C][api:134]: API Server:
[09:34:18][C][api:135]:   Address: alarm-status-display.local:6053
[09:34:18][C][api:139]:   Using noise encryption: NO
[09:34:18][C][homeassistant.binary_sensor:038]: Homeassistant Binary Sensor 'Living Room PIR Front'
[09:34:18][C][homeassistant.binary_sensor:039]:   Entity ID: 'binary_sensor.living_room_pir_front'
[09:34:18][C][mdns:084]: mDNS:
[09:34:18][C][mdns:085]:   Hostname: alarm-status-display

I would really appreciate some pointers to understand how to make this work.

Cheers,

Joel.

Home assistant binary_sensor.living_room_pir_front connection?

text_sensor:
      
  - platform: homeassistant 
    name: "doorbell"
    entity_id: binary_sensor.doorbell
    id: doorbell

Thanks!

I can now see the sensor state being reported to the ESPHome device - Its reporting either ‘on’ or ‘off’

What do I need to do in ESPHome to switch a relay so that it follows the status?

Cheers.

text_sensor:
      
  - platform: homeassistant # автоматизация для кнопки на улице
    name: "doorbell"
    entity_id: binary_sensor.doorbell
    id: doorbell
    on_value:               
      - if:
          condition:
            text_sensor.state:
              id: doorbell
              state: 'on'
          then:
            - switch.turn_on: sound_test

Sorry i dont follow…

I now have a couple of things created in the ESPHome yaml

text_sensor:
  - platform: homeassistant 
    name: "Living Room PIR Front"
    entity_id: binary_sensor.living_room_pir_front
    id: livingroompirfront

switch:
  - platform: gpio
    pin: D1
    name: "Living Room PIR Front Relay"
    id: livingroompirfrontrelay

The ‘text_sensor’ is getting the state of the PIR - this works and it creates a sensor inside HA which updates automatically.

The ‘switch’ controls the relay, this also works and creates a switch in HA, when i slide the switch, the relay operates.

What i still cannot work out is how to make the two work together so that the text_sensor is directly controlling the relay without having to do anything inside HA.

Apologies, it may be so obvious that I’m just totally looking past it…

Cheers,

Joel.

then:
            - switch.turn_on: livingroompirfrontrelay
text_sensor:
  - platform: homeassistant 
    name: "Living Room PIR Front"
    entity_id: binary_sensor.living_room_pir_front
    id: livingroompirfront
on_value:               
      - if:
          condition:
            text_sensor.state:
              id: doorbell
              state: 'on'
          then:
            - switch.turn_on: livingroompirfrontrelay

the syntax is incorrect as I am writing from the phone now. my very first example definitely works for you. change only id