Help with light automation script

I just installed Hass.io on a Ubuntu 64bit VirtualBox a few days ago and have been trying to get this one automation I found to work. I did a lot of Googling and I have a very basic grasp of formatting and such. All I’ve done outside of installing was link my Hue bridge and set my location for the weather.

Here’s my configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
script:
       sunrise:
       alias: Simulate sunrise
       description: 'fade lights to simulate sunrise'
       sequence:
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 10
              color_temp: 500
          - delay:
                  seconds: 30
          - alias: Sun Bulb On
            service: light.turn_on
            data:
             entity_id: light.bedroom
             brightness_pct: 20     
             color_temp: 465
          - delay:
               seconds: 30
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 30
              color_temp: 430
          - delay:
               minutes: 3
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 40
              color_temp: 395
          - delay:
               minutes: 3
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 50
              color_temp: 360
          - delay:
               minutes: 3 
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 60
              color_temp: 330
          - delay:
               minutes: 3
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 70
              color_temp: 295
          - delay:
               minutes: 3
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 80
              color_temp: 260
          - delay:
               minutes: 3
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 90
              color_temp: 225
          - delay:
               minutes: 3
          - alias: Sun Bulb On
            service: light.turn_on
            data:
              entity_id: light.bedroom
              brightness_pct: 100
              color_temp: 185
               
              input_boolean:
                 sunrise_enabled:
                     name: "Morning Sunrise"
                     initial: on
                     icon: mdi:weather-sunset
                 sunrise_weekend:
                     name: "Weekend Sunrise"
                     initial: off
                     icon: mdi:calendar-blank
              input_datetime:
                 sunrise_time:
                     name: "Start sunrise at"
                     has_time: true
                     has_date: false
automation: 
          - alias: "Cool artificial sunrise"
            trigger:
             platform: template
             value_template: "{{ states('sensor.time') ==(states.input_datetime.sunrise_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
  
condition:
          - condition: state
            entity_id: input_boolean.sunrise_enabled
            state: 'on'
          - condition: or
            conditions:
          - condition: state
            entity_id: input_boolean.sunrise_weekend
            state: 'on'
          - condition: time
            weekday:
               - mon
               - tue
               - wed
               - thu
               - fri
action:
          - service: script.turn_on
            entity_id: script.sunrise

It’s an automation to make the lights gradually turn on at a set time, with controls for it on your dashboard. I’m not sure if this is the best way to do it, but after checking 5 different ones on Google it seemed like exactly what I was after.

using the file editor I got from the add-on store it finally got it to where it say’s my syntax is all correct. The way the automation’s controlled is you create a card and there are 3 entities that should show up in the drop down when you type sunrise when adding the entities to the new card. When I type sunrise into the entity box though nothing comes up. Just to see, added all 3 manually, these are the 3 that it shows should come up on the web site I found the tutorial on.

input_boolean.sunrise_enabled
input_datetime.sunrise_time
input_boolean.sunrise_weekend

and on my dashboard I get “Entity not available:” for all of them.

I see all 3 in the code, and from what I’m picked up, the scripting looks like it should be okay. All I can think of is the formatting’s off, but if it is I don’t see where. And if it’s something different I’m just lost. I copied the code from the web site with the tutorial. Outside of changing the light entries to my light name, it’s a line for line copy. I re-read the tutorial 3 times and went over the code line by line numerous times. No idea what I should be looking for. I want to learn how to write scripts from scratch, but that’s going to take me a good while. So in the mean time I’m trying to figure this out.

I know this is a very n00bish thing but after playing with it for 2 days I’m not seeming to make any progress and I’m out of ideas. So I thought I’d come ask for help.

If anyone wishes to help me out, thanks in advance.

You use them in your automation, but you didn’t define them anywhere. Check the documentation for input booleans here to find out how to create input booleans.

Nevermind, I see you got them in your config. However, they are indented too far. Indentation is very important in YAML. Decreasethe indentation so that input_boolean: is on the same lwvel as script:

like this:

script:
........
input_boolean:
  sunrise_enabled:
    name: "Morning"
    initial: on
    icon: mdi:weather-sunset
  sunrise_weekend:
    name: "Weekend"
    initial: off
    icon: mdi:calendar-blank
input_datetime:
  sunrise_time:
    name: "Start sunrise at"
    has_time: true
    has_date: false
1 Like

Thank you for the reply! I’ve been Googling for the past 3 1/2 hours trying to figure out one last issue here with no luck.

input_datetime:
  sunrise_time:
    name: "Start sunrise at"
    has_time: true
    has_date: false

This one’s still not coming up as an entity I can add. I didn’t find anything on Google that helped, so I took a wild guess and tried making the 2nd line say sunrise_time: ‘02:35’ I also tried removing the line and the last 2 completely and added initial: ‘02:35’ . As it was something I found on another alarm clock thread I found. I used 02:35 so I could test and see if it would trigger the alarm, nothing happened.

I’ve never actually seen this automation in action, but I’m assuming how it works is on the card input_datetime: let’s you set the alarm time. It’s not showing up as an entity for me but the other 2 are so I don’t know what to do next. The more I read on Google I’m starting to piece tiny bits here and there together, but nothing so far is helping me understand the problem here. On my own I’d figure it out but it’ll probably take me 2 weeks. And I’m trying to get this alarm up and running this week so I can use it.

I changed the indentions just like Burningstone said, which fixed the issue with 2 of them not showing up. If anyone can see where the formatting’s wrong I’m all ears. I moved stuff around in attempts to figure it out but nothing did anything.

Do you see any error under Configuration → Logs? If you go to Developer Tools → States can you find the entity there?

You also need to create the time sensor, the docs are here.

In general it’s not a good idea to google for your issues, HA evolves extremly fast and therfore most guides online are often outdated and may not work anymore with the changes that happened in the meantime. You’d rather read the docs and search this forum.

Thanks for replying again

I didn’t mention in my posts last night, but I checked the states and didn’t see the datetime entity. I just checked, right after I went to bed I got 3 errors in the log

Setup failed for sunrise: Integration not found.

3:40:00 AM – setup.py (ERROR) - message first occurred at 3:40:00 AM and shows up 6 times

Unable to set up dependencies of default_config. Setup failed for dependencies: input_datetime

3:40:00 AM – setup.py (ERROR)

Invalid config for [input_datetime]: expected a dictionary for dictionary value @ data[‘input_datetime’][‘has_date’]. Got False expected a dictionary for dictionary value @ data[‘input_datetime’][‘has_time’]. Got True expected a dictionary for dictionary value @ data[‘input_datetime’][‘name’]. Got ‘Start sunrise at’ expected a dictionary for dictionary value @ data[‘input_datetime’][‘sunrise_time’]. Got None. (See /config/configuration.yaml, line 102). Please check the docs at https://www.home-assistant.io/integrations/input_datetime

3:40:00 AM – config.py (ERROR) - message first occurred at 3:40:00 AM and shows up 2 times

guessing the datetime errors were because I needed a time sensor like you said? No idea why it’s saying “Setup failed for sunrise: Integration not found.” Sunrise is the script so apparently there’s something off in the code.

I created the time sensor, restarted the box and still not seeing the datetime, but I’m going to play with it and read more on the official documentations to see what I can figure out. Thanks again you’ve been very helpful

You have indentation errors. Can you please show your current code?

That was it! I looked over the code again and saw a line that was 1 spacing off, I guess I can’t rely on the text editor’s green check mark telling me my formatting correct. It’s coming up on my card now, but I see there are error when I restart the box pertaining to this script. What I learned from you, I’m sure it’s due to my indentation. So I’m going to go over it line by line and make sure. If I have any issues I’ll be back tonight, but I want to at least try and figure this out on my own. Thank you again for being so helpful.

EDIT

Yes thank you! It was the formatting, my history with anything close to this is autoexec.bat and config.sys back in the days. So the exactness required here’s throwing me off. Not sure why but I was still getting errors so I moved the automation to the automations.yaml and put automation: !include automations.yaml. Not sure if this is a preferred method or not (need to go read up) but it’s working, at my configuration file’s a lot less cluttered.

1 Like