Really struggeling with even the simplest automation

Hey, I’m new to Home Assistant and I’m going insane with even the most simple config, reading through countless examples (so many different suggestions and formating for the same thing) but I cannot get this working.

I’ve set up a scenes and they respond as expected when I activate them from Overview.
However I’m struggling really bad with automation of even the simple stuff I’m starting out with.

First step is simply turning the lights off at a specific time, I have this in my automations.yaml but it does nothing :frowning:

- id: '1531863387944'
  alias: 'God natt'
  trigger:
    platform: time
    at: '23:00:00'
  condition:
    condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  action:
    service: scene.turn_on
    entity_id: scene.lys_av

Please help me or point me in the right direction.

Sorry about bad formating, thought I did this right, working on it…

I just like to add, if I trigger the automation manually it works, it turns off the light. So I’m guessing there is something wrong with the trigger/condition config.

This is another case of “YAML is very sensitive to indentation”! (:wink: This trips up new users all the time. Hang in there - you’ll get it!)

So, if you look here, you’ll see that weekday: should line up directly below condition: time. So:

- id: '1531863387944'
  alias: 'God natt'
  trigger:
    platform: time
    at: '23:00:00'
  condition:
    condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  action:
    service: scene.turn_on
    entity_id: scene.lys_av

That should fix it.

pnbruckner, thank you for your time.

Unfortunatly it’s still not working, if I trigger the scene manually it turns off the light, and if I trigger the autmation manually it turns off the light. But it’s not triggered by the time :frowning: (I changed the time to 2 minutes later and reload automation, even tried rebooting home assistant)

This is pretty basic. Are you sure the time is set correctly on your home assistant system, and both the OS and your home assistant configuration agree about timezone? You might want to dump out your home-assistant.log file. There might be some clues in there, and the timestamps (which are reported in EDIT: local time) might help you determine if at least the clock is set correctly. To check the timezone setting, try using a native command on the OS to output the time to see what that looks like in local time. In home assistant, maybe the easiest way to check is to look at the logbook - those times are shown in local time, too.

Another way to maybe tell is to enter the following in the template editor:

{{ utcnow() }}
{{ now() }}

The first will show the current time (from home assistant’s perspective) in UTC, and the second will show it in local time.

1 Like

I’m running Home Assistant in a docker on qnap nas, the time is correct, but I see some errors thrown there

2018-07-25 20:53:57 WARNING (MainThread) [homeassistant.components.http] You have been advised to set http.api_password.
2018-07-25 20:54:22 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/discovery.py", line 167, in scan_devices
    results = await hass.async_add_job(_discover, netdisco)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/discovery.py", line 193, in _discover
    netdisco.scan()
  File "/usr/local/lib/python3.6/site-packages/netdisco/discovery.py", line 69, in scan
    self.daikin.scan()
  File "/usr/local/lib/python3.6/site-packages/netdisco/daikin.py", line 32, in scan
    self.update()
  File "/usr/local/lib/python3.6/site-packages/netdisco/daikin.py", line 46, in update
    sock.bind(("", UDP_SRC_PORT))
OSError: [Errno 98] Address already in use

EDIT: The log stams correct time, but the code you gave me is 2 hours off, that would explain my days of failed testing… now to fix it…

Although you’ll probably want to correct those problems, they shouldn’t explain why this automation doesn’t run when you expect. Have you tried removing the condition block temporarily? Also, try setting the time ahead like maybe 10 minutes (I mean 10 minutes from now) and restart HA (just to make sure it doesn’t miss the time)?

Wait, that doesn’t make sense. The home-assistant.log should be using the same time as now() reports, even if it’s wrong. They should agree. Is the timezone offset shown by the output of now() (i.e., the ‘+/-xx:xx’ part) correct for your local timezone?

I had UTC set as timezone, I changed it to correct timezone and it’s working now. Thank you so much for your help. Now moving on to more scripts and automation. I will probably be back shortly with new problems :smiley:

One last question though, I just created a new simple turn on some lights (scene) at sunset, without conditions, I guess that’s where the condition: [] comes from, but in all my reading of different examples I often see - in front of some commands, like the service: command below, but it’s not used in the above script ? Why ? this is very confusing for new users…

 - id: '1532545100483'
  alias: Solnedgang
  trigger:
  - event: sunset
    platform: sun
  condition: []
  action:
  - service: scene.turn_on
    entity_id: scene.lys_stue

trigger, condition, action, and many other parameters will accept either a list or a single entry. So you might enter a list of things, a list of one thing, or just one thing. I.e., they’re flexible. When you enter a list of things (even just one), each “thing” has a dash before the first part of the “thing” to indicate this “thing” is a list item. So:

trigger:
  - platform: abc

is a list of one entry, whereas:

trigger:
  platform: abc

is not a list, but just one entry. They are different, don’t mistake that. But, in this case, trigger accepts either a list or a single item, so either works. But be careful, although this generally works in many places, it doesn’t necessarily in all. That’s where the documentation for each component and platform comes in.

BTW, another confusing aspect is whether or not the dash is indented. Actually, it doesn’t matter. What matters is the indentation of the keyword. So:

trigger:
  - platform: abc

is the same as:

trigger:
- platform: abc

Note that in both cases platform is indented from trigger. That’s what’s important, not where the dash is.

Hopefully that helps (and doesn’t further confuse you! :slight_smile:)

1 Like

Thank you so much for your help. You got me going, now I already have a script that turns off the lights and pause my Sonos system when AppleTV is playing, and when I hit pause on AppleTV the living room lights are turned on again. Now to add some more conditions… Better make backup before I start braking stuff :smiley:

1 Like