Trying my first automation

Hi all,

I’ve been doing some basic things in Home Assistant, and I would like to get into a deeper knowledge of it. I love it and I want to learn all I can, but for now, I’m stucked in basic things.

My problem is that I want to create a button in the Lovelace which lets me turn on a switch (which activates an elecctrice heater) for a certain period of time (like a timer).

I’ve been searching in the community blog and there are a lot of people doing this, but in my case it does not work, and I don’t know why it is.

The post I’ve been using for my automation is the following: https://community.home-assistant.io/t/edit-yaml-through-lovelace/135386

For the moment I have this; in the config.yaml:

# Proves de temporitzador
input_boolean:
  radiador_timer_enable:
    name: Timer Enable
    #initial: on
    icon: mdi:timer

input_number:
  radiador_timer:
    name: On Timer (mins)
    #initial: 30
    min: 1
    max: 120
    step: 1
    mode: box
    icon: mdi:alarm

In my scripts.yaml there is this:

script:
    alias: heater timer script
    sequence:
    - delay: '00:{{ states("input_number.temp_cuina") | int }}:00'
    - service: switch.turn_off
      entity_id: switch.cuina_rad

And my automation.yaml is:

  - id: '001'
    #name: Heater Off Delay
  - alias: switch_heater_offdelay
    trigger:
    - platform: state
      entity_id: switch.cuina_rad
      to: 'on'
    condition:
    - condition: state
      entity_id: input_boolean.radiador_timer_enable
      state: 'on'
    action:
    - service: script.turn_off
      entity_id: script.heater timer script
    - service: script.heater timer script
#turning off timer enable cancels timer
  - id: '002'
  - alias: au_heater_cancel_tmr
    trigger:
    - platform: state
      entity_id: input_boolean.radiador_timer_enable
      to: 'off'
    action:
    - service: script.turn_off
      entity_id: script.heater timer script
    #name: Heater Off Cancels Timer
  - id: '003'
  - alias: au_heater_offcancelstimer
    trigger:
    - platform: state
      entity_id: switch.cuina_rad
      to: 'off'
    action:
    - service: script.turn_off
      entity_id: script.heater timer script

All the yaml seems correct, but when I validate the configuration in the control server, there appears the following errors:

Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: not a valid value for dictionary value @ data[‘action’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: not a valid value for dictionary value @ data[‘action’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: not a valid value for dictionary value @ data[‘action’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 13).

I don’t know why is that, could someone help me?

Thanks in advance.

In all three automations you have

script.heater timer script

If you go to Developer Tools / States I think you will find the correct name is

script.heater_timer_script

From your first automation

    - service: script.turn_off
      entity_id: script.heater timer script
    - service: script.heater timer script

Doesn’t make sense
Delete the line

- service: script.heater timer script

perhaps ?

Also, none of your automations turn the script on.
I think in your first automation

- service: script.turn_off

Should be

- service: script.turn_on

Hi Mark,
very ambitious entrance for a newbie :wink:
I’am also willing to learn so let’s try to bring the things together.

  1. your script has no id, e.g. heater_timer could be one:
script:
  heater_timer:
    alias: heater timer script
    sequence:
    - delay: '00:{{ states("input_number.temp_cuina") | int }}:00'
    - service: switch.turn_off
      entity_id: switch.cuina_rad
  1. therefor your automation has an entity_id which isn’t defined. entity_id never have spaces whereas friendly name can have spaces
    action:
    - service: script.turn_off
      entity_id: script.heater timer script
    - service: script.heater timer script

It’s auto generated if you create the script through the UI, otherwise it’s not required.

Hi honikos,

I think it could be much more than my level is, but if you help me, for sure we could bring things together!

  1. I tried to use the script you brought me, but now it says that there is something wrong; as jivesinger says, it could be that the id is autogenerated, and therefore, if I use the seacrh entity in the file editor I have this:
entity_id: script.script
  1. What you are saying is right! I changed the automation, so my automation now looks like this:
  - id: '001'
    #name: Heater Off Delay
  - alias: switch_heater_offdelay
    trigger:
    - platform: state
      entity_id: switch.cuina_rad
      to: 'on'
    condition:
    - condition: state
      entity_id: input_boolean.radiador_timer_enable
      state: 'on'
    action:
    - service: script.turn_off
      entity_id: script.script

#turning off timer enable cancels timer
  - id: '002'
  - alias: au_heater_cancel_tmr
    trigger:
    - platform: state
      entity_id: input_boolean.radiador_timer_enable
      to: 'off'
    action:
    - service: script.turn_on
      entity_id: script.script
    #name: Heater Off Cancels Timer
  - id: '003'
  - alias: au_heater_offcancelstimer
    trigger:
    - platform: state
      entity_id: switch.cuina_rad
      to: 'off'
    action:
    - service: script.turn_off
      entity_id: script.script

This also solves what jivesinger was saying; I’ve changed all the entity_id to the code above.

But I’m having some of the errors that I was having before, here I copy the errors:

Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).
Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 13).

Thank both of you for your help and time!

Search in your Developer Tools for the entity_id of your template sensor. In the state-section just type in script.

You need to change

entity_id: script.script

in your automations to

entity_id: script.heater_timer_script

assuming your script hasn’t changed from your first post.

As for your errors, remove the hyphen before alias.
So change from this

  - id: '002'
  - alias: au_heater_cancel_tmr

to this on all three of your automations

  - id: '002'
    alias: au_heater_cancel_tmr

I’m not trying to be rude, but that makes absolutely no sense

Oh ! You mean like this to find the name ?

exactly

:+1:

1 Like

That’s what I get, the name of it is script.script

jivesinger

It is all solved and now the configuration seems valid. I will try it when I reach home and I will inform you of the state!

jivesinger
honikos

Thank you both of you! Finally I could solve my problem, it was a lot easier that I was planning, but I don’t know if I did a good job explaining my problem…

I went to the integration documentation for the input number in the home assistant: https://www.home-assistant.io/integrations/input_number/ and I copied the last example which is:

# Example configuration.yaml entry using 'input_number' as a delay in an automation
input_number:
  minutes:
    name: minutes
    icon: mdi:clock-start
    initial: 3
    min: 0
    max: 6
    step: 1

  seconds:
    name: seconds
    icon: mdi:clock-start
    initial: 30
    min: 0
    max: 60
    step: 10

automation:
 - alias: turn something off after x time after turning it on
   trigger:
     platform: state
     entity_id: switch.something
     to: 'on'
   action:
     - delay: "00:{{ states('input_number.minutes') | int }}:{{ states('input_number.seconds') | int }}"
     - service: switch.turn_off
       entity_id: switch.something

When I changed my entity_id to the correct switch, I posted in my lovelace panel the entities like it is in the image:
image

And it’s working!!!

Thanks a lot for your support and I’m very sorry if I did not explained myself very well.

1 Like