Automation template: Invalid data for call_service expected int for dictionary value @ data['position']

Hi all,

Thanks all in advance for you help, this is my first post in the community.

I’m facing an automation error that I’m unable to resolve. I’ve tried many combinations and differnt approaches but I keep getting following error:

2020-01-29 21:56:00 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.programa_persiana. Invalid data for call_service at pos 2: expected int for dictionary value @ data['position']

I’m trying to setup an automation to set blinds at specific position at specific times.

  • 6:20 set cover.persiana_cocina at position 90
  • 19:30 set cover.persiana_dormitorio at 35
  • 21:30 set cover.persiana_cocina at 35.
  • In all cases, a notification should also be sent informing of the hour it was executed at.

And here my failing automation:

- id: '1579878523506'
  alias: Programa-persiana
  description: ''
  trigger:
  - at: '19:30'
    platform: time
  - at: '21:56'
    platform: time
  - at: '6:20'
    platform: time
  action:
  - service: cover.set_cover_position
    data_template:
      entity_id: cover.persiana_cocina
      position: '{% if trigger.now.hour == 21 %} 35 {% endif %}'
  - service: cover.set_cover_position
    data_template:
      entity_id: cover.persiana_cocina
      position: '{% if trigger.now.hour == 6 %} 90 {% endif %}'
  - service: cover.set_cover_position
    data_template:
      entity_id: cover.persiana_dormitorio
      position: '{% if trigger.now.hour == 19 %} 35 {% endif %}'
  - data_template:
      message: "Programa-persiana triggered at {{ trigger.now.hour }}"
    service: notify.ha_besalu

The thing is that the first cover cover.persiana_cocina is correctly set to the position but then the error is thrown and no notification is sent. I’ve tried many things without any luck.

Thanks for your help!

Well, if the hour not matches, the position gets nothing, but needs an int.

I think it’s easier to create 3 automations, also easier to read.

If this triggers at 19:30 or 6:20, the first service call will look like this after the template is complete:

  action:
  - service: cover.set_cover_position
    data:
      entity_id: cover.persiana_cocina
      position:

Because hour != 21, nothing would be put into the position field.

You should just do a single service call to cover all 3 possible triggers.

- id: '1579878523506'
  alias: Programa-persiana
  description: ''
  trigger:
  - at: '19:30'
    platform: time
  - at: '21:56'
    platform: time
  - at: '6:20'
    platform: time
  action:
  - service: cover.set_cover_position
    data_template:
      entity_id: cover.persiana_cocina
      position: >- 
        {% if trigger.now.hour == 21 %} 
         35 
        {% elif trigger.now.hour == 6 %} 
          90
        {% else %}
          35
        {% endif %}

Now all cases are covered and position will never be an empty value.

1 Like

Thank you so much, I fully understand it now. I finally created 3 separate automations.