WeMo Rules

I have never used rules on the wemo as I found them buggy but would like to to do it from HA. Ideally I would like to turn on/off my light x days of the week at x time. i tried the below but never got it to work, and how do I add the days of the week?

automation:
alias: Turn off light
trigger:
platform: time
hours: 2
minutes: 45
seconds: 0
action:
service: homeassistant.turn_off
entity_id: switch.light

I’m new to HA also, but have had lots of success so far with some simple rules.
If you are new to yaml, the indenting is very important… This is a guess at what might work for you:

automation:
  - alias: 'Turn off light'
    initial_state: True
    trigger:
      platform: time
      after: '15:59'
    condition: time
      weekday:
        - mon
        - tue
    action:
      service: switch.turn_off
      entity_id: switch.light #if this is the name of your switch

fails at the bold part with ERROR:homeassistant.util.yaml:mapping values are not allowed here

Hey @johnsnow

Check out: https://home-assistant.io/getting-started/automation-trigger/
Try specifying the time with seconds:

after: '15:59:59'

now it’s line weekday: that has error mapping values are not allowed here

It’s in the docs that thefrenchmatt linked to above. The condition requires a before or after and can then take a weekday…

Docs:

condition: time
# At least one of the following is required.
after: '15:00:00'
before: '02:00:00'
weekday:
  - mon
  - wed
  - fri

You might want to think about it and change the trigger (perhaps related to the sun or sunset) and then put the times and the days of the week in the conditions. This page is quite good: https://home-assistant.io/getting-started/automation-create-first/

1 Like

But since it has the after it should work. I don’t want to use sun based rules

One is a condition and one is a trigger. They work differently.

Okay so this is what I have so far and now it seems to fail at actions

automation:
  - alias: 'Turn off Light'
    initial_state: True
    trigger:
    platform: state
    entity_id: switch.light
condition: time
before: '02:00:00'
weekday:
  - mon
  - wed
  - fri
    action: 
      service: switch.turn_off
      entity_id: switch.light

First a warning: with the YAML language, indenting (spaces, never tabs) really matters.
1)
To help you there’s yamllint, install and run it (regularly) on the ha folder : I use ‘yamllint ~/.homeassistant -parsable’ and you can create a config file, ha is not as strict as other implementations of YAML.

Even if doesn’t apply here, I see you’re really trying and can’t help but feel you’ll soon need templates.
2) test them in the h-a dev module
3) Use “hass --script check_config -i automation”

Try to always think of step 1 and 3 before any restart (to be sure you haven’t missed a space or a quote), automations are the hardest to debug, I often end up having to move every file out, and put them back in progressively to figure out which one is the problem.


Now back to your automation.

‘Quoting’ will not always feel logic, and I often made the mistake to think I had something figured out, screwing up my automations in the process.

MOST values don’t need quoting, but True/true/False/false/on/off/0/1 will have a different effect depending on if they are quoted or not (and both are often used)
I like this short summary : http://symfony.com/doc/current/components/yaml/yaml_format.html

Using ‘True’ (string) or True (boolean) are both fine, but sometimes ha (core + components) expect a specific type. It cannot distinguish what you meant, You can also look at binary sensors to get a feel of how booleans are different : a binary sensor can only have 2 values, but it’s mentioned those can be On/Off True/False etc.

You should read first about the syntax, then start testing working examples (snippets in the wiki are less useful than looking this here : https://home-assistant.io/cookbook/

I understand you want to have something work fast and now, but you’ll get exponentially more frustrated if you don’t first learn those basics. I didn’t want to either, and now I see how much time I could have saved :wink:

This will also help you understand how you can format multiline ouput : http://stackoverflow.com/a/21699210/6305035


So, finally, here’s your automation in a way to be able to copy/paste & adapt it for your next steps :

automation:
  - alias: Turn off Light
    initial_state: 'True'
    trigger:
      platform: state
      entity_id: switch.light
    condition:
      condition: and
      conditions:
        - condition: or
          conditions:
            - condition: time
              before: '02:00:00'
            - condition: time
              after: '23:50:00'
        - condition: time
          weekday:
            - mon
            - wed
            - fri
    action: 
      service: switch.turn_off
      entity_id: switch.light

Thanks, thats exactly what i needed. I wasn’t looking for a hand out since I know it will only get more complex and if I can’t do the basics I’ll be in trouble.

1 Like

I think you ARE getting busy, not checking-in for 4 days straight :wink:

I think you got why, with YAML, the true devil lies in the little details : indenting, a few control characters, and actually more so than the logic of HA.

And at some point you’ll need either templating or AppDaemon for your automations. And if AppDaemon is very nice, it’s not for everyone, and requires learning some Python : that’s why I started to create stuff that can just be copy/pasted in the dev module.

I joined the HA bandwagon in April, back when a simple mistake would just keep it from starting. I always wondered why!!!?? (only pushing me even harder to learn what’s YAML). Winter came when it became possible (even a feature!) to ignore that cold & hard “no-go”.

Skipping over the basics is possible, but as you said, it will just make things harder.

So instead of letting you down, I’ve tried it my way, and build a different approach to it altogether.

I saw it as a way to learn faster some of the ‘more complex’ functions… and so without breaking everything you worked for.

How? take it like puzzle, look at it once, then cut some functions you want/need learning : that’s how you’ll see templating can work in a lot of places, and most likely for stuff you didn’t even expect to be possible.

This should bring more fun in your automations, the wiki will provide you with static pieces of code, or full sets from others (which were a huge help) but it’s still ‘up to you’ if you need them to be much moar.

With time, I’ll try to add stuff and make it easier to read… but then your winter may be long, especially each of my weeks were so full of learnings : I had to stop a little and celebrate thanksgiving in some way %)

End of the year is always busy time so i haven’t had much time to tinker and learn. Got a few days off this holiday so will try to take a stab at this and see if i break things until it starts to work :stuck_out_tongue: