Template rendered invalid service in working automation

Hi!

I created an automation with service_template. The automation works but in the log there is “Template rendered invalid service:” without any additional info.
Is it a bug or my configuration error?

This is my automation:

- action:
  - data:
      entity_id: switch.vent_podval
    service_template: >-
      {% if (states('sensor.podval_humidity') | float) > 70 %}
      switch.turn_on
      {% elif (states('sensor.podval_humidity') | float) < 68.5 %}
      switch.turn_off
      {% endif %}
  alias: vent_podval
  condition:
  - condition: state
    entity_id: input_boolean.vent_podval_manual
    state: 'off'

  id: '1524387299867'
  trigger:
  - entity_id: sensor.podval_humidity
    platform: state
  - event: start
    platform: homeassistant

Remove the last double-quote character at the end of the template.

Also you have no service if between 68.5 and 70. That’s the bigger problem.

Remove the last double-quote character at the end of the template.

It was copy-paste error in my post. At the server conf it is OK. I wrote that this automation works without problem - there is error at the log only.

Also you have no service if between 68.5 and 70. That’s the bigger problem.

It is for hysteresis. If the humidity is between 68.5 and 70 nothing to do - the switch state doesn’t change

Then add a condition so it doesn’t run for those in between values, because the errors you are seeing are probably due to it running then but there’s no else so there’s no service specified.

Specifically, like this:

- action:
  - data:
      entity_id: switch.vent_podval
    service_template: >-
      {% if (states('sensor.podval_humidity') | float) > 70 %}
      switch.turn_on
      {% else %}
      switch.turn_off
      {% endif %}
  alias: vent_podval
  condition:
  - condition: state
    entity_id: input_boolean.vent_podval_manual
    state: 'off'
  - condition: or
    conditions:
    - condition: numeric_state
      entity_id: sensor.podval_humidity
      above: 70
    - condition: numeric_state
      entity_id: sensor.podval_humidity
      below: 68.5

  id: '1524387299867'
  trigger:
  - entity_id: sensor.podval_humidity
    platform: state
  - event: start
    platform: homeassistant

Actually, the more I think about it, maybe change the trigger instead:

- alias: vent_podval
  id: '1524387299867'
  trigger:
  - platform: numeric_state
    entity_id: sensor.podval_humidity
    above: 70
  - platform: numeric_state
    entity_id: sensor.podval_humidity
    below: 68.5
  - event: start
    platform: homeassistant
  condition:
  - condition: state
    entity_id: input_boolean.vent_podval_manual
    state: 'off'
  action:
    service_template: >-
      {% if (states('sensor.podval_humidity') | float) > 70 %}
      switch.turn_on
      {% else %}
      switch.turn_off
      {% endif %}
    entity_id: switch.vent_podval

I also reordered the lines to be more readable.

1 Like

It works!!!
Thank you!

1 Like