Cant seem to get a LED to turn on when connected to the API,
Any ideas?
api:
encryption:
key: ""
on_connect:
- light.turn_on:
id: led
brightness: 100%
red: 0%
green: 100%
blue: 0%
effect: none
on_disconnect:
- light.control:
id: led
state: on
effect: ERROR
aceindy
(Aceindy)
September 1, 2024, 9:33am
2
I think we need the whole yaml in order to be able to give any help.
Maybe this yaml helps; this is for a sonoff switch.
When the relay (named “light_1”) is off, the LED (called led_1) is on and vise versa.
It also has a physical button (on GPIO00), which will toggle light_1 and led_1 too.
esphome:
name: sonoff-switch-ip50
comment: "IP50"
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_iotpw
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: sonoff-switch-ip50_FB
password: "fallback"
captive_portal:
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption
# Enable Over The Air updates
ota:
- platform: esphome
# Disable logging
logger:
baud_rate: 0
logs:
sensor: ERROR
duty_cycle: ERROR
binary_sensor: ERROR
light: ERROR
# Binary Sensors.
binary_sensor:
- platform: gpio
pin:
number: GPIO00
mode: INPUT_PULLUP
inverted: True
id: button_1
on_press:
then:
- light.toggle: light_1
light:
- platform: binary
name: "My Light"
id: light_1
output: relay_1
on_turn_on:
then:
- output.turn_on: led_1
on_turn_off:
then:
- output.turn_off: led_1
output:
- platform: gpio
pin: GPIO12
id: relay_1
- platform: gpio
pin: GPIO13
id: led_1
Note: led_1 is connected to GPIO13
Ok sorry I figured it out, managed to find it in the API examples,
I needed to use
on_client_connected:
and
on_client_disconnected:
# Enable Home Assistant API
api:
encryption:
key: ""
on_client_connected:
- light.turn_on:
id: led
brightness: 100%
red: 0%
green: 100%
blue: 0%
effect: none
on_client_disconnected:
- light.control:
id: led
state: on
effect: ERROR
1 Like
nickrout
(Nick Rout)
September 1, 2024, 10:36am
5
So you read the documents.
1 Like
oh boy, guess I should have seen that one coming.
1 Like