Running Script with Automation not working

Hi

I have created (unsuccessfully) an automation to run a script based on battery state, but it’s not working.

Can anyone please help?

Automation

- id: morning_on
  alias: Morning
  trigger:
    - platform: state
      entity_id: sensor.iphone_battery_state
      from: "Charging"
      to: "Not Charging"
  action:
    - service: script.turn_on
      data:
        entity_id: script.morning

Script

morning:
  alias: Morning
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.bedside
        min_mireds: 153
        max_mireds: 500
        brightness: 1
        hs_color:
        - 33.767
        - 84.314
        rgb_color:
        - 255
        - 160
        - 39
        xy_color:
        - 0.561
        - 0.404
    - delay: 0:05
    - service: light.turn_off
      data:
        entity_id: light.bedside

Go to developer tools > states and check what the actual state of the sensor in the trigger is… it’s likely charging and discharging.

The state displayed in the frontend is the “friendly state” so to speak, but the actual state is at developer tools > states.

Hi. No it’s definitely exactly as I’ve entered it.

Does the script work on its own? I don’t think you can define the colours 3 ways at the same time.

1 Like

You see Charging or Not Charging here at developer tools > states?

Also, you don’t need hs_color, rgb_color, and xy_color all defined in the light.turn_on service call. Just use one. Not sure what would happen with all of those defined.

Edit: ha, jinx @anon43302295

1 Like

as @anon43302295 said, color is mutually exclusive. Meaning you can only have hs_color, xy_color, or rgb_color. Not all 3. Also, min_mireds and max_mireds are not valid in the service.

YOu have 1 of 3 options:

1

morning:
  alias: Morning
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.bedside
        brightness: 1
        hs_color:
        - 33.767
        - 84.314
    - delay: 0:05
    - service: light.turn_off
      data:
        entity_id: light.bedside

2

morning:
  alias: Morning
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.bedside
        brightness: 1
        rgb_color:
        - 255
        - 160
        - 39
    - delay: 0:05
    - service: light.turn_off
      data:
        entity_id: light.bedside

3

morning:
  alias: Morning
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.bedside
        brightness: 1
        xy_color:
        - 0.561
        - 0.404
    - delay: 0:05
    - service: light.turn_off
      data:
        entity_id: light.bedside
1 Like

The states in the automation are correct. They list as Charging and Not Charging

2 Likes

Interesting, good to know. I’m so used to everything being lowercase. When I originally responded I wasn’t even paying attention to the service call tbh

3 Likes

Yes

Thanks to all who responded about the colour issue. I’ve left it with just the rgb values and it works.

I needed to ensure I had the correct colour and created a scene in the Hue app, then created a scene in HA and just copied the values from the HA scene hence why all three colour sets were in the original.

All good now. Thank you for the advice.

1 Like

If you have defined a Hue scene, you can activate it from Home Assistant (there’s no need to duplicate it in Home Assistant). For example:

  - service: hue.hue_activate_scene
    data:
      group_name: 'Dining Room'
      scene_name: 'Relax'

This is more efficient than using a Home Assistant scene, especially if the scene has several lights. That’s because Home Assistant only needs to transmit one command, to activate the Hue scene, and each light that is part of that scene already knows how it should behave.

1 Like

Great, I wasn’t aware of that. Thank you.