Hi everybody,
can you please help me create an automation that will run on my ESPHome
device triggered by an input_boolean
from Home Assistant?
Home Assistant → test_powerbank.yaml
input_boolean:
test_powerbank:
name: "Powerbank LED"
icon: "mdi:led-outline"
ESPHome (nodeMCU v2
) relevant code
text_sensor:
- platform: homeassistant
id: power_led
entity_id: input_boolean.test_powerbank
# (...)
deep_sleep:
run_duration: 30sec # (currently 10min for testing purposes)
sleep_duration: 15min
light:
- platform: binary
name: Powerlight
output: light_output
output:
- id: light_output
platform: gpio
pin:
number: D5
The idea is that this device will be powered off most of the time; when it wakes up, it should check whether input_boolean.test_powerbank
is on
or off
. Depending on this, it should switch the id: light_output
light (or, for the actual project I am planning, a switch) to the same state. So if input_boolean.test_powerbank == on
, the light (later switch) should set itself to the same state - and vice versa for off
.
I tried adding this underneath entity_id: input_boolean.test_powerbank
, but that did not work.
on_turn_on:
light_turn_on:
- id: light_output
on_turn_off:
light_turn_off:
- id: light_output
I assume it could be solved by using templates-lambdas, but I don’t seem to understand the syntax and/or just cannot make this work.
Thank you in advance for your ideas
(btw., is this the right approach? The idea is to connect this device to both a powerbank and to a 3V3 fairy lights strip (powered by 2 or 3 AA batteries); if one wants them to be on, they change the switch on Home Assistant - then wait for the ESPHome device to wake up, check the status, and act accordingly. Switching is supposed to be done via gpio switch
and an 2N2222 transistor
that will be connected to one pin on the nodemcu and replace the physical on/off switch on that fairy lights power supply)
EDIT: bonus question: IF we were to use templates-lambdas, anyway, perhaps there could be an addition: if Home Assistant cannot be reached (no wifi, Home Assistant down, or any other reason), also turn the fairy lights to off
. So if they are on and something goes wrong, they will still be switched off upon the next wake up.