First automation not working

Hi,
I have installed hassio, with some funcional rest componente switches, and the zigbee add-on, but I’m struggling now with the first automation. (the switch are working OK, but not with automation, I tried a “sensor” as trigger, and now “time” as in following exemple:

Could you look at it and see is something is wrong…
Thanks!

in configuration.yaml:

switch:
  - platform: rest
    name: "Table"
    scan_interval: 5
    resource: http://192.168.0.212/relay/0
    body_on: 'turn=on'
    body_off: 'turn=off'
    is_on_template: '{{ value_json.ison == true}}'
    headers:
      content-type: application/x-www-form-urlencoded
  - platform: rest
    name: "Ceiling 1"
    scan_interval: 5
    resource: http://192.168.0.212/relay/1
    body_on: 'turn=on'
    body_off: 'turn=off'
    is_on_template: '{{ value_json.ison == true}}'
    headers:
      content-type: application/x-www-form-urlencode

in automations.yaml:

- id: '1536979650570'
   alias: table On
   trigger:
   - at: '14:24:00'
     platform: time
   condition: []
   action:
   - data:
       entity_id: switch.table
     service: switch.turn_on

In the same states page, make sure your automation is on as well.

1 Like

I dont have any automation appearing in the states page… ?

I am assuming you used the UI automation editor to make the automation. Restart HA or reload automations from the Configuration > General page. Then check the states page again.

1 Like

Yes, first with automation editor and restart and then doing it directly on the automation file, and restart… And I have: automation: !include automations.yaml on my configuration file…

Great! Now looking at the states page, is automation.table_on state set to ‘off’ or ‘on’?

1 Like

Under states/current entities, I have a “group.all_automations” on, but all the automations on this group are from zigbee and all are on… Is this the place to look for the automation?

Filter the entities of the states page with automation, might make it easier.

It is not there. And is strange that wen I try to use the automation editor it save the code to the automation file, but dos not give the option to edit the automation I just saved… is this normal?

No clue since I don’t use it. Sounds like it isn’t really saving. Is it giving an error when you save?

1 Like

No error in the editor, and the alteration is visible in the file, I guess HA is riding the file, because if I make code error it give me the feedback on the validation…

That sounds really unlikely… Save some really obvious error into your automations.yaml and go into the config panel->general->“check config”. See if it picks it up. Maybe your editor is showing you errors but homeassistant isn’t actually reading that file. Otherwise hass isn’t really restarting…

Also, i’d format the automation this way (at least this is what works in mine):

- id: '1536979650570'
  alias: table On
  trigger:
    platform: time
    at: '14:24:00'
  action:
    service: switch.turn_on
    data:
      entity_id: switch.table
1 Like

@Pedro_Cordeiro So you add the automation using the automation editor, and afterwards you cannot edit it or see it in the same editor?

If you manually check your automation.yaml file, do you see the automation?

Can you post the content of your automation.yaml file?

In your first post, the indention is wrong. See https://www.home-assistant.io/docs/automation/editor/#migrating-your-automations-to-automationsyaml
id should have the same indention as alias, trigger, condition and action.

1 Like

-I made some really obvious error into automations.yaml for testing thats the result:

Error loading /config/configuration.yaml: while scanning a simple key in “/config/automations.yaml”, line 3, column 1 could not find expected ‘:’ in “/config/automations.yaml”, line 4, column 1

-pasted your formatting

-restart on app

restart by fiscal disconnecting the Raspberry

Same result…

  • So you add the automation using the automation editor, and afterwards you cannot edit it or see it in the same editor? yes (and after that tried to wright the code miself)
    -If you manually check your automation.yaml file, do you see the automation? yes:

/config/configuration.yaml:

- id: '1536979650570'
  alias: table On
  trigger:
    platform: time
    at: '14:24:00'
  action:
    service: switch.turn_on
    data:
      entity_id: switch.table

And thats the result, no automation!

its disappointing, probably, something stupid I did…

I have this log:
019-07-16 21:44:01 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/configuration.yaml contains duplicate key “automation”. Check lines 18 and 69.

I had some code from zigbee pen with an automation section on the configuration.yaml: probably this is the problem, right?
Do I move all this code to the automation.yaml, group.yaml…respectively, or can I put it all in a zigbee.yaml ?
Thanks for you patience…

#zigbee
input_boolean:
  zigbee_permit_join:
    name: Allow devices to join
    initial: off
    icon: mdi:cellphone-wireless

timer:
  zigbee_permit_join:
    name: Time remaining
    duration: 600 # Updated this to the number of seconds you wish

sensor:
  - platform: mqtt
    name: Bridge state
    state_topic: "zigbee2mqtt/bridge/state"
    icon: mdi:router-wireless

group:
  zigbee_group:
    name: Zigbee
    entities:
      - input_boolean.zigbee_permit_join
      - timer.zigbee_permit_join
      - sensor.bridge_state

automation:
  - id: enable_zigbee_join
    alias: Enable Zigbee joining
    hide_entity: true
    trigger:
      platform: state
      entity_id: input_boolean.zigbee_permit_join
      to: 'on'
    action:
    - service: mqtt.publish
      data:
        topic: zigbee2mqtt/bridge/config/permit_join
        payload: 'true'
    - service: timer.start
      data:
        entity_id: timer.zigbee_permit_join
  - id: disable_zigbee_join
    alias: Disable Zigbee joining
    trigger:
    - entity_id: input_boolean.zigbee_permit_join
      platform: state
      to: 'off'
    action:
    - data:
        payload: 'false'
        topic: zigbee2mqtt/bridge/config/permit_join
      service: mqtt.publish
    - data:
        entity_id: timer.zigbee_permit_join
      service: timer.cancel
    hide_entity: true
  - id: disable_zigbee_join_timer
    alias: Disable Zigbee joining by timer
    hide_entity: true
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.zigbee_permit_join
    action:
    - service: mqtt.publish
      data:
        topic: zigbee2mqtt/bridge/config/permit_join
        payload: 'false'
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.zigbee_permit_join 

Just a small thing that gave me a problem when I tried my first automation using the automation editor:

I clicked the Save button, but found the that automation did not seem to be saving correctly. Only after a few tries did I notice that I had to scroll up to the top of the automation editing window to see that there was an error message displayed at the top that was preventing it from saving. There was no indication that the Save had or hadn’t worked otherwise.

1 Like

Yes, that’s the problem. You have multiple automation: sections, so it will only load automations from the last one (which is empty)… You’ve got to find the other one and delete it.

Since you have
automation: !include automations.yaml
the first thing I’d do is to check your automations.yaml file and check to see if you put another automation: in there… If you did, you need to delete it… Otherwise check in other places in your config.yml.

PS to answer your question, you need to put this into your automation.yml and delete the automation: part if you are using !include. Leave the other stuff as it is

  - id: enable_zigbee_join
    alias: Enable Zigbee joining
    hide_entity: true
    trigger:
      platform: state
      entity_id: input_boolean.zigbee_permit_join
      to: 'on'
    action:
    - service: mqtt.publish
      data:
        topic: zigbee2mqtt/bridge/config/permit_join
        payload: 'true'
    - service: timer.start
      data:
        entity_id: timer.zigbee_permit_join
  - id: disable_zigbee_join
    alias: Disable Zigbee joining
    trigger:
    - entity_id: input_boolean.zigbee_permit_join
      platform: state
      to: 'off'
    action:
    - data:
        payload: 'false'
        topic: zigbee2mqtt/bridge/config/permit_join
      service: mqtt.publish
    - data:
        entity_id: timer.zigbee_permit_join
      service: timer.cancel
    hide_entity: true
  - id: disable_zigbee_join_timer
    alias: Disable Zigbee joining by timer
    hide_entity: true
    trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.zigbee_permit_join
    action:
    - service: mqtt.publish
      data:
        topic: zigbee2mqtt/bridge/config/permit_join
        payload: 'false'
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.zigbee_permit_join 
1 Like

Problem solved!
With all the automations in the automations.yaml, everything is working.
Thanks for you patience and support!
This was a good lesson… I need to make a nice tutorial about the basis of file organisation python, indentation etc…

1 Like

Before you do that, I suggest you review the existing documentation. For example, this section would’ve saved you some time:

My Integration Does Not Show Up

configuration.yaml does not allow multiple sections to have the same name.

1 Like