Need help with an input_boolean helper

Here’s my project:
I have a VL35L0X distance sensor on a Wemos D1 Mini that is located a few inches from my trash bins. When the bin is present, a helper, ‘input_boolean.trashbin_present’, goes to true. When the bin is not present the helper goes to off. This part works fine.

I wanted to add an LED to the Wemos D1 Mini to indicate the bin presence status. If ‘input_boolean.trashbin_present’ is on, turn on the LED. if the boolean helper is off, then turn off the LED.

Below is my yaml code. What did I miss? Is the script not running?

# Trash bin detector

substitutions:
  devicename: trashbin

esphome:
  name: ${devicename}
  on_boot:
    priority: -100.0
    then:
      - script.execute: test_trashbin

esp8266:
  board: d1_mini

logger:
    level: VERBOSE

api:

ota:

packages:
  wifi: !include common/wifi.yaml
  
web_server:
  port: 80
  
    
##################################

i2c:
  sda: D2
  scl: D1
  frequency: 800kHz

sensor:
  - platform: vl53l0x
    name: ${devicename}VL53
    address: 0x29
    update_interval: 5s
    long_range: true


binary_sensor:
  - platform: homeassistant
    name: ${devicename} Present
    id: trashbinstatus
    entity_id: input_boolean.trashbin_present


# A switch is to operate something external,
# like an LED attached to a gpio. 
switch:
  - platform: gpio
    name: ${devicename} LED
    pin:
      number: D3
      mode: output
      #inverted: True
    id: led


#################################################    
# Script to test the trashbin_present helper
script:
  - id: test_trashbin
    mode: queued
    then:
      - if:
          condition:
            binary_sensor.is_on: trashbinstatus
          then:
            - switch.turn_on: led
          else:
            - switch.turn_on: led


########## Get the WiFi details ##########
text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${devicename} IP Address
      id: ip
    ssid:
      name: ${devicename} SSID
    mac_address:
      name: ${devicename} Mac Address

Your binary sensor in the ESPhome config is designed to pull that entity from HA, not send it to HA. Therefore if the sensor is not changing in HA then your LED won’t work. Is there a reason you don’t just do it all within ESPhome and only send the bin status to HA?

Thanks for the quick reply.

binary_sensor:
  - platform: homeassistant
    name: ${devicename} Present
    id: trashbinstatus
    entity_id: input_boolean.trashbin_present

The ‘input_boolean.trashbin_present’ is set on or off by automations in Home Assistant.

I am using the ‘current state node’ in Node Red to read the ‘input_boolean.trashbin_present’ helper where I process the status. Basically, if the bin is present on Sunday Evening at 17:00, I blink a button on a HASP device over MQTT. If the bin is missing, I stop the blinking button and reset the foreground/background colors to the “normal” fg/bg. I do all this with eleven nodes in Node Red. The complexity of the same in ESPHome is way beyond my pay scale. Besides, I have never had good results using MQTT in ESPHome.

But, all that works, so I know that the automations in Home Assistant are turning the input_boolean.trashbin_present on and off.

What I can’t figure out is how to turn on/off the LED on the Wemos D1 Mini in response to the input_boolean.trashbin_present on or off.

If you’re certain the LED works and it’s just a question of linking it to the sensor status:

binary_sensor:
  - platform: homeassistant
    name: ${devicename} Present
    id: trashbinstatus
    entity_id: input_boolean.trashbin_present
    on_press:
      then:
        - switch.turn_on: led
    on_release:
      then:
        - switch.turn_off: led

Thanks. For some reason, I didn’t equate the binary.sensor with the on_press function.
Works fine now.

1 Like

@stevemann in some circumstances you want to check the status of the switch or binary in HA in which case the following is useful

text_sensor:
  - platform: homeassistant
    name: Pump Status
    internal: False
    entity_id: switch.shelly_watertankpump
    on_value:
      then:
        lambda: |-
          if(x == "on") {
            auto call = id(pumpled).turn_on();
            call.perform();
          } else {
            auto call = id(pumpled).turn_off();
            call.perform();
          }

As soon as I see ‘lambda:-’, my brain freezes.

On the other hand, I have a project in mind that I have already done with Arduino and I would like to port it to ESPHome. As I understand it, I could port my Arduino code using lambda.

@stevemann as an old bloke I just copied somebody else! However, there is a deep satisfaction in a yawning understanding of a new subject. I have realised that my next skills in this HA journey are NodeRed and C++ !