New to HA - My first Automation

Hi Guys,

So I have just setup Hassio and got my z-stick and components included in HA and its time to do my first automation going.

Im totally green so go easy on me

I have an fibaro wall plug that I want to control. I want it to turn on when the sun goes down. Should be easy enough, but…

This is my code:

automation:
alias: Light_on_sunset
trigger:
platform: sun
event: sunset
Action:
Service: homeassistant.turn_on
entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch

image|615x458

What am I doing wrong?

You are not using the code format block of the forum‘s editor, so nobody can tell …

Hi Sondrev,
First – welcome to Home Assistant! You will love it and this community is awesome – extremely helpful.
One thing though, this community complains when people paste code that is not properly formatted. So click on the </> in the menu bar to paste code.
I have the Fibaro switches – generally happy. I did have to disable the LED when powered off to please my wife while sleeping – you do that by settings in Configuration / Zwave.

Here is sample of how I trigger via motion sensor (Fibaro) and turn on Light switch plug (Fibaro).

- alias: 'Motion in LR'
  trigger:
     platform: state
     entity_id: binary_sensor.fibaro_system_fgms001zw5_motion_sensor_sensor
     to: 'on'
  action:
     service: homeassistant.turn_on
     entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch

BTW, you will also want to verify YAML with tools like LINT. I used to have problems with tabs inserted. I use Cloud9 IDE Add-in via Hassio add-ins (makes editing much easier). And when things break, check the HhomeAssistant.log file.

Enjoy, and ping back if your need help. I’m a student of HomeAssistant.

~Bryan

Thank you for the replies!

My apologies. I see now how that first code lost its formatting when I posted it. It looked fine when I pasted it, but i guess the “whitespace” goes away when you post it…

In my Config.yaml I have a line that says:
automation: !include automations.yaml
in the automations.yaml file I have the following code: (hopefully with formatting)

automation:
  - alias: Light_on_sunset
    trigger:
        platform: sun
        event: sunset
    Action:
        Service: homeassistant.turn_on
        entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch

From what I can see this looks fairly similar to what you have written. Any ideas why I am getting the error message?

Should i use “New entity id” or “Old entity id”? The old entity id is almost similar but with “_2_0” on the end

I am using the “check Configuration” feature inside of HA which gives me an error message

I haven’t done much with automations, but I do know that yaml file are very particular about indentations and capitalization.

Normal indents are 2 spaces, most things are lower case. i.e. action and service.

# Example of entry in configuration.yaml
automation:
# Turns on lights 1 hour before sunset if people are home
# and if people get home between 16:00-23:00
  - alias: 'Rule 1 Light on in the evening'
    trigger:
      # Prefix the first line of each trigger configuration
      # with a '-' to enter multiple
      - platform: sun
        event: sunset
        offset: '-01:00:00'
      - platform: state
        entity_id: group.all_devices
        to: 'home'
    condition:
      # Prefix the first line of each condition configuration
      # with a '-'' to enter multiple
      - condition: state
        entity_id: group.all_devices
        state: 'home'
      - condition: time
        after: '16:00:00'
        before: '23:00:00'
    action:
      service: homeassistant.turn_on
      entity_id: group.living_room
1 Like

Well you pointed out a very important thing: Capitalization
Thank you carbuthn!

I wont forget that any time soon…3 hours of trial and error for a Capital letter in “Action” and “Service”

If automations are in a separate file (as they should be) you have to omit the “automation:” label and move the definitions to top-level. File should look like:

- alias: Light_on_sunset
  trigger:
    platform: sun
    event: sunset
  action:
    service: switch.turn_on
    entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch

Also: Mind uppercase/lower case, usually it’s all lower-case. And - this type of automation can easily be modelled using the embedded automation editor (at the “Configuration” menu). And finally, I used “switch.turn_on” instead of “homeassistant.turn_on”, because the only entity is a switch, so no need to use the generic service.

Thank you m0wlheld.

I want to learn to use the config. This will give me experience using it for future projects.

While I have your attention:

I want to control the the wallplug(s) in a few ways:

  • Light on when the sun settles - Check
  • Light off when it rises (sun) - Check
  • Light off when there is no one home (device tracker)
  • lift off if no movement is present (fibaro multisensor)

How would i organize this? Do i make several automations that work parallell or should all of them be in one automation in a “while/if” statement ?

Don’t know about the device tracker, I’ll assume that you group the tracked devices and check if the group is ‘home’ or ‘not_home’.

For the motion sensor: It depends. I have motion sensors that are binary_sensor type, so they are ‘on’ if movement is present and ‘off’ otherwise. I think that Fibaro is different with various numeric states.

So the trigger would be based on numeric state being at, above or below a certain value. Or you could use a template trigger, with an evaluation expression that resolves to True or False.

@Sondrev one source I forgot to mention is the cookbook section of the docs Cookbook examples.

It may take some time to go through them, but you can learn a lot.