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?
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.
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++ !