Help with automation for outside lights

This is my automation for my outside lights. The dashboard says they are on but they are not.
If I go to the dashboard turn them off then back on then they come on… Not sure what I missed here.
It does fire every night but no lights.

Thank you!

- alias: 98 - Turn on Outside lights
  description: ""
  trigger:
    - platform: sun
      event: sunset
      offset: "00:15:00"
  action:
    - service: light.turn_on
      entity_id: light.outside_front_lights
      data_template:
        xy_color:
          ["0.{{ range(1, 100000)|random }}", "0.{{ range(1, 100000)|random }}"]
        brightness: 85

You have the template for xy_color: on a separate line so you need to include a line-continuation character.

        xy_color: >
          ["0.{{ range(1, 100000)|random }}", "0.{{ range(1, 100000)|random }}"]

BTW, the syntax you are using is a bit dated (for example, data_template was deprecated in favor of data many versions ago). Here’s the current syntax:

    - service: light.turn_on
      target:
        entity_id: light.outside_front_lights
      data:
        xy_color: >
          ["0.{{ range(1, 100000)|random }}", "0.{{ range(1, 100000)|random }}"]
        brightness: 85

For future reference, when you encounter automation issues, check the automation’s trace. It will provide clues to help debug the problem.

Thank you! I cannot edit automations directly from the automation screen or debug them they are not in the automations.yaml file they are all seperate files in an automation directory :slight_smile: Even when I put them in the automation.yaml I still cannot debug or ‘trace’ them as they have no unique id.

Just add an ID to them, what it is doesn’t matter as long as it is unique


- id: climate away mode on
  alias: climate away mode on

1 Like

All my automations are also created with a text editor and I add a unique_id so the automation will have traces (there’s also an option to control how many traces are stored; the default is ten). However, ensure the value of unique_id is a valid slug. In other words it’s the same naming rules as for entity_id (alphanumeric characters with no spaces or hyphens, underscore is permitted).

1 Like

Ok so this is what I get from that and it’s not working:

params:
  domain: light
  service: turn_on
  service_data:
    xy_color:
      - '0.9014'
      - '0.69234'
    brightness: 85
    entity_id:
      - light.outside_front_lights
  target:
    entity_id:
      - light.outside_front_lights
running_script: false
limit: 10

Apparently it doesn’t like this part:

service_data:
    xy_color:
      - '0.9014'
      - '0.69234'
    brightness: 85

If I take that out it works… hummmmmm

I believe xy_color should contain a list of two numeric values (float) but the trace shows two numeric strings.

Change the template to this:

        xy_color: >
          [ 0.{{ range(1, 100000)|random }}, 0.{{ range(1, 100000)|random }} ]

1 Like

Had to remove brightness that what was causing it not to work now…

@123 Thank you for the xy_color change that worked!!

These are my attributes for this light:

h: 292
hue: 292
s: 77
saturation: 77
x: 0.3519
'y': 0.20202

Couldn’t use h or hue went with xy that works… there is no brightness so it fails… tried saturation and it says ‘NO’… so not sure how I’m going to get that part… hummmmmmmm

Glad to hear it helped to solve the problem. Please consider marking my post above with the Solution tag.

Regarding the brightness attribute, it might be something specific to the model of light bulb you are using. I say that because I just tested it with a Philips Hue bulb ( setting both xy_color and brightness in the same service call) and it worked.

1 Like

YES I appreciate it!! I’ll play with it somemore… it’s how you learn. If I don’t end up with the brightness I’ll probably live LOL

Thanks again to all of you!

1 Like

Just in case anyone else is ever looking for something similiar here is the final:

- alias: 98 - Turn on Outside lights
  id: 98 - Turn on Outside lights
  trigger:
    - platform: sun
      event: sunset
      offset: "00:15:00"
  action:
    - service: light.turn_on
      target:
        entity_id: light.outside_front_lights
      data:
        xy_color: >
          [ 0.{{ range(1, 100000)|random }}, 0.{{ range(1, 100000)|random }} ]

    - service: notify.mobile_app_sm_f926u1
      data:
        message: "TTS"
        title: "Turning on Outside Lights."
        data:
          channel: alarm_stream_max
          ttl: 0
          priority: high

- alias: 99 - Turn Outside lights Off
  id: 99 - Turn Outside lights Off
  trigger:
    - platform: sun
      event: sunrise
      offset: "-00:15:00"
  action:
    - service: light.turn_off
      entity_id: light.outside_front_lights
  mode: single

If you are interested, you can consolidate the two automations.

  • Assign each trigger an id.
  • Use a choose to determine which of the triggers occurred based on its id value.

That’s interesting but not sure how to do that… LOL

- alias: 98 - Control Outside lights
  id: 98 - Control Outside lights
  trigger:
    - id: sunset
      platform: sun
      event: sunset
      offset: "00:15:00"
    - id: sunrise
      platform: sun
      event: sunrise
      offset: "-00:15:00"
  action:
    - choose:
        - conditions: "{{ trigger.id == 'sunset' }}"
          sequence:
            - service: light.turn_on
              target:
                entity_id: light.outside_front_lights
              data:
                xy_color: >
                  [ 0.{{ range(1, 100000)|random }}, 0.{{ range(1, 100000)|random }} ]
            - service: notify.mobile_app_sm_f926u1
              data:
                message: "TTS"
                title: "Turning on Outside Lights."
                data:
                  channel: alarm_stream_max
                  ttl: 0
                  priority: high
       default:
         - service: light.turn_off
           entity_id: light.outside_front_lights
  mode: single

EDIT

Correction. Fixed typo.

WOW Thank you. I’m not a programmer know just about enough to be dangerous but as I read through that it makes perfect sense to me! Yes I will use that! Thank you! It’s gripping about the - is part but I’m assuming that’ll be okay. “Property is not allowed” LOL

Can you elaborate because I’m not sure what you are referring to?

Well, nutz! That’s a typo I made …

Change it to id (I’ll correct the posted example).

That’s okay! I appreciate it! Just trying to learn ‘better’ ways to doing things that make sense and I don’t have 300 files when I only need 100… :slight_smile: LOL

That tells me it’s working the way it should! Thank you!

Capture