Turn on light at sunset

I would like to turn on a light with a specific scene at sunset everyday. What may be wrong with this Automation?

- id: '1573782707182'
  alias: Night
  description: ''
  trigger:
  - event: sunset
    platform: sun
  condition: []
  action:
  - data:
      Living Room Shelf Lamp:
    service: light.turn_on
  - data:
      Living Room-Night:
    service: light.lifx_set_state

You’re not using the attribute “entity_id” when mentioning the light:

- id: '1573782707182'
  alias: Night
  description: ''
  trigger:
  - event: sunset
    platform: sun
  condition: []
  action:
  - data:
      entity_id: light.living_room_shelf_lamp  <--- I just made this entity up, you need to find yours
    service: light.turn_on
  - data:
      entity_id: light.living_room_night  <--- Same here.
    service: light.lifx_set_state  <--- I've also never heard of this service, but I don't have LIFX lights.
1 Like

This looks like something created with the Automation Editor.

Thank you. With regards to ‘light.lifx_set_state’, I don’t know what it is either. I thought maybe it allowed me to call a LIFX scene I created.

@Taras, Yes, it was.

service.lifx_set_state is a valid service but if you review the documentation you’ll see it’s for calling the entity_id of one or more LIFX lights (not a scene).

The current state of the Automation Editor leaves lots of room for improvement. I recommend you learn how to use VS Code preferably with the Home Assistant extension. Are you currently using the HASS.IO version of Home Assistant? If so, VS Code is available as an add-on.

@Taras, thanks. I had read that documentation, but did not completely understand it.

Yes, I’m using hass.io; I’ll get that add-on.

The set state service for a Lifx light allows you to change the attributes of the light (e.g. colour and brightness) without changing the state (on/off). For other manufacturer’s lights you can only change the brightness or colour when using the light turn on service.

I use the set state service set light brightness attributes depending on the outside light level. Then other automations turn the lights on/off triggered by movement.

Not an essential service but I find it handy.

1 Like

Unfortunately it does not run on an RPi if that’s what @ScottS has Hass.io installed on. There’s a note about it in the known limitations section for the VSCode addon page.

However there is an extension for VS Code to connect a stand alone installation of VSCode to HA that works pretty well.

Even better - I really like the Cloud9 IDE addon. It’s the bees knees. Runs on a PI and has a built in terminal negating the need to run another SSH terminal addon. Addon installs it preconfigured for your HA instance.

Thanks @tom_l, I do use that functionality through my Android Tasker app and plugin, so this will come in handy.

I’m running it as a VDI on my Windows computer. I’ll give both add-on’s a try. thanks.

If you use VS Code, I suggest using this extension:

https://marketplace.visualstudio.com/items?itemName=keesschollaart.vscode-home-assistant

2 Likes

Got Cloud9 running, though I get an alert in the log, which I have started a new thread here:

https://community.home-assistant.io/t/cloud9-log-alert/148621

Edit: Solved; guess all the add-on’s have this error; ignoring.

Having read this, I installed vsc on win 10
Added the home assistant addon showed it where my files were and it went through and found two itty bitty faults in my files that check config missed.
That’s really quite impressive.
I also like that similar to notepad++, it does auto completion, but across all files and all entities.
Thanks for the recommendation.

If you install this vscode extension it will show you your indentation inconsistencies too:

The Config Helper extension also identifies indentation errors although maybe not as attractively as the ‘indent rainbow’ extension. In the following screenshot, I’ve added an extra space in front of friendly_name and immediately the last word on the line gets the’ wavy gravy’ treatment. By hovering over it, the popup reveal the cause is bad indentation.

Screenshot%20from%202019-11-15%2021-33-39

Here’s the same indentation error but with the indent-rainbow extension installed. Wavy gravy + popup + super-obvious red bar.

Screenshot%20from%202019-11-15%2021-43-38

The other cool thing about indent-rainbow is that it forces multiples of 2 spaces by default. So even though the following is ‘technically’ correct yaml it alerts you to a style inconsistency.

Untitled

Off subject code question using vscode…

In the below code, the brightness setting (50) does not have single quotes around it, should it? VScode did not present an error for it.

I also do not have an id specified for this device. It’s my understanding that device id is no longer required as we’re now using the device name…correct?

  - service: homeassistant.turn_on
    entity_id: light.living_room_shelf_lamp
    data:
      brightness_pct: 50
      transition: 3

the brightness setting (50) does not have single quotes around it, should it?

Nope.

  • A number is expected as the value. Depending on the key: sometimes a string is expected. You should quote these or if a special character like ‘%’ is used. Or a special word like ‘on’ or ‘off’ (unquoted these will evaluate to true and false).

Look at this part of the docs:

Screenshot_2019-11-17%20Remote%20Raspberry%20Pi%20GPIO

  • The VSCode extension is not aware of type (number vs string), just correct key: value pair syntax and indentation.
  • Home assistant can usually deal with a quoted number anyway.

IDs are a UI editor thing and can be omitted if you never intend to use it. I have a bad habit of including them in all my automations as I started out very briefly with the UI editor.

- id: lounge_lamp_green_flash # Not required unless using the UI editor, so why do I do it? Habit.
  alias: 'Green Flash at Sunset'
  trigger:
...

If you use IDs at all, I’d make them completely different than the alias. It’s very misleading when you go and try to figure out the name for your automation. Is it automation.lounge_lamp_green_flash? Nope. It’s the very un-intuitive automation.green_flash_at_sunset.

I tend to omit the IDs and write my aliases as they are going to be viewed in the dev states page. It’s easier to remember the name when you go to write things that use that automation, and it’s easier to find it in the code after seeing it refereneced in the HA log file.

1 Like