Need super basic (KISS) turn on light example

I have looked at many youtube examples and written instructions on how to code an automation setup, but they always have way to much other details that muddy up the water.

I just need the most basic snipped of code to show me how to turn on a light (configured as a sonoff switch) that will activate at a given time. I am a experience programmer, but just need the basics here to get me started in the right direction.

Thank You.

P.S. After modifying the automation.yalm file, do I need to restart any services?

I hope this is KISS enough :wink:

automation:
  - alias: Turn on wake-up light on workdays
    id: 'towulow'
    trigger:
      platform: time
      at: '06:35:00'
    condition:
      - condition: state
        entity_id: 'binary_sensor.workday_sensor'
        state: 'on'
    action:
      - service: light.turn_on
        entity_id: light.nightstand
        data:
          transition: 900 # 900 seconds = 15 minutes
          brightness: 254

Remove the condition block if not required.

Don’t forget to add the time sensor:

sensor:
  - platform: time_date
    display_options:
      - 'time'

You need to restart Home Assistant when editing these files.

Thank you Florian for your responds, for it is very much appreciated.

I have added this stripped down version of your code to my configuration.yalm file:

#####################
sensor:
- platform: yr
- platform: time_date
display_options:
- ‘time’
####################

And this is what my automations.yalm consists of:
######################

  - alias: Turn on Main Light
    id: 'towulow'
    trigger:
      platform: time
      at: '13:17:00'
    action:
      - service: light.turn_on
        entity_id: switch.main_switch

#########################.

But it does not work.

I do notice here is that I have the time_zone set up to my correct region in the config.yalm file. And my Raspberry shows the correct time, but the the time shows a +9 hr difference on the main Hassio panel. But even when I change the time in the code to turn on the light to reflect this it still does not work

FYI, you don’t need the time sensor just to get an automation to trigger at a specific time.

Your issue is you’re using the light.turn_on service with a switch. You either need to use the switch.turn_on service (preferable), or you could use the homeassistant.turn_on service. FYI, the latter can turn on any type of entity.

1 Like

Sorry, I assumed you’ve configured your Sonoff switch as a mqtt light.

Let’s update the automation to use switch.turn_on and fix the indentation (shift everything 2 spaces to the left):

- alias: Turn on Main Light
  id: 'toml'
  trigger:
    platform: time
    at: '13:17:00'
  action:
    - service: switch.turn_on
      entity_id: switch.main_switch

Regarding the incorrect time:
Did you configure time_zone using one of these values listed in the column tz?

Thanks pnbruckner!

Switching from light.turn_on to switch.turn_on (since I was using a Sonoff switch) resulted in making this automation finally work.

But I had to add +9 hr to the time so it would coincide with what the time was showing up on the main Hasio page.

Florian:
I have the configuration.yalm file set to:
time_zone: America/Los_Angeles

But I know know why there is a time difference. I am using another raspberry pi to display the AppDaemon on a touch screen panel. And this time is set correctly. But now I just need now to change the correct time on the Hassio raspberry pi to also reflect the correct time.

Thanks all for your help. I am now literally out from the darkness with my switch.main_switch being able to turn on.

2 Likes

One addition to the question: “After modifying the automation.yalm file, do I need to restart any services?”

This isn’t the only way. When modifying the automations you can just use the “Reload automations” under Configuration/Configuration reloading.

chrio
that is differently a time saver. Thank you for that great tip!

Also if you have a .yalm file you are doing it wrong. It is .yaml