Confused about ESPHome API, Triggers, and HA Services

Below is my ESPHome Config for an LED strip that lights my stairs. It works great for the PIR sensor attached to it, but I would also like to use HA triggers to create more lighting effects like addressable rainbow or other things mentioned in the docs.

What I am confused most about is the yaml for accessing api > on_press > for a service. I’m not sure if that makes sense. What I ideally want to happen is for when motion is detected on camera A (sensor.camera_a), for this light, (light.led_stairs) to show addressable rainbow or some other effect.

I currently have the light turn on a different color using scenes & automation. A scene for the LED light color and then automation for when the motion is detected. However, I can’t do any fun effects via automation/scenes. If I can, please correct me. If not, it looks like I can do that via the ESPHome yaml. Can anyone offer any help?

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO16
      mode: INPUT_PULLDOWN_16
    name: "Stair_motion"
    id: stair_motion
    device_class: motion
    on_press:
      - if:
          condition:
            binary_sensor.is_on: stair_motion
          then:
            - light.turn_on: led_stairs_light
            - delay: 7s
            - light.turn_off: led_stairs_light
          else:
            - wait_until:
                binary_sensor.is_on: stair_motion
    
light:
  - platform: neopixelbus
    type: GRB
    pin: GPIO3
    num_leds: 60
    name: "led_stairs_strip"
    id: led_stairs_light
    variant: WS2812

Try

    on_press:
      then:
        - light.turn_on: led_stairs_light
    on_release:
      then:
        - delay: 7s
        - light.turn_off: led_stairs_light

In home assistant you have to add the esphome sketch from the integrations page. Then you will have an entity light.led_stairs_strip and you can turn them on and off from there too.

Thanks for your reply to both of my treads, Mike! I think I may have explained this incorrectly, here’s a pseudo-yaml of what I’m looking to do.

api:
  password: 1234

# HA Sensor Trigger
on_press:
  - homeassistant.service:
       service: motion.backyard
       then:
         - light:
               platform: wled
               effect: addressable_rainbow # Or scan, or any other effect

Under the API header do I need to import the sensors from HA that I want to use? As in, create a binary sensor for each camera motion sensor I want to use?

I’m using Frigate, so MQTT would also be a possible use case. So to trigger this ESPHome sensor within the ESPHome yaml, I believe I just need to trigger an automation from “on_json_message”, such as this example.

In retrospect, MQTT seems like the easier option, but I am now curious how to solve the original question of importing a sensor in my HA config into my ESPHome yaml.

mqtt:
  # ...
  on_json_message:
    topic: the/topic
    then:
      - light.turn_on:
          id: living_room_lights

You import sensors, just like adding any other kind of sensor, but using the platform homeassistant.

Holy crap, how did I miss that page in the docs?! Thanks, Andrew. There are so many ESPHome pages I sometimes get lost… :grimacing:

2 Likes

Most of the time that I visit the site, I don’t see the list of all the different sensors etc, because it’s giving me a changelog since the last time I visited.

1 Like