Turn on light at sunset

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

I’d make them completely different t

Good point. I picked that at random. Unfortunately it was one of my early automations. However I do the opposite and always make them the same now for precisely that reason.

- id: mains_power_fail_alert
  alias: 'Mains Power Fail Alert'
  initial_state: true
  trigger:

One day when I have some spare time I may delete all the automation ids.

1 Like

Using quotes…I now get it. Where is that in the docs? I tried searching for ‘using quotes’, etc. and could not find it.

ID’s, good to know I can name it, not just present a number. Probably a good thing to use it in case the UI editor becomes more robust someday.

Thanks @SteveDinn, makes sense.

Where is that in the docs?

I’ve never seen it. I think it is assumed knowledge that strings are quoted numbers aren’t. Could be in the YAML specification (i.e. not just for home assistant but everything that uses YAML).

Scott this is “your” thread we appear to have hi-jacked, the discussion seems to be relevant to you so that’s great, but it is we who should be appologising to you (not enough that we’ll stop though :cough: :rofl: )

1 Like

All good; wanted to make sure this shouldn’t be a new thread as this has gone off-subject.

Automation IDs…if I create my own within the configurator, the UI editor does not recognize that it can be edited. So unless you create the automation in the editor, I guess adding such in the configurator doesn’t matter. As you said, time to get rid of the those IDs :slight_smile:

1 Like