What is wrong in my automation? Never had this error. Since 0.107.1 I see this error:
2020-03-19 23:36:11 ERROR (MainThread) [homeassistant.components.automation] Motion Detection - Hallway On Off: Error executing script. Invalid data for call_service at pos 2: Service does not match format <domain>.<name>
2020-03-19 23:36:43 ERROR (MainThread) [homeassistant.components.automation] Motion Detection - Hallway On Off: Error executing script. Invalid data for call_service at pos 2: Service does not match format <domain>.<name>
2020-03-19 23:37:10 ERROR (MainThread) [homeassistant.components.automation] Motion Detection - Hallway On Off: Error executing script. Invalid data for call_service at pos 2: Service does not match format <domain>.<name>
The if statement in the template for service_template does not have an else clause. Are you sure that one of the expressions (if or elif) is always true? If not, then the template will result in an empty string, which of course is not a valid service.
If you want it not to do anything if neither of those expressions are true, then one way to do that is to make it call a script that does nothing. E.g.:
You said it didn’t happen before, implying that you used this automation before 0.107.1 and didn’t see those errors. The reason I’m asking is before we’ve started to make some changes in the script/automation infrastructure and I’d like to know if those changes had something to do with it. I can’t see how they could, but maybe I’m missing something. It would be helpful to know.
before on 0.106.x I didn’t see any errors. Now on 0.107.1 I see those errors.
Sorry for not understanding you before… I checked the automation. and this must be the correct one then:
I see that in the script I made some changes and its wrong.
condition:
- condition: state
entity_id: switch.mqtt_scene_goodnight
state: "on"
Means this entity MUST on otherwise automation will not run.
- service_template: >-
{% if (states.binary_sensor.node_17.state) == 'on' and (states.switch.mqtt_scene_goodnight.state) == 'off' %} switch.turn_on
{% elif (states.binary_sensor.node_17.state) == 'off' and (states.switch.mqtt_scene_goodnight.state) == 'off' %} switch.turn_off
{% endif %}
entity_id: switch.meek_hallway
and here I say when the entity is always off… thats not gonna work. This must be ON or remove that part, because condition is already a strict thing that the entity must be on otherwise skip automation.
Than this automation is correct one. I totally didn’t see it at all… haha blonde…
###########################################################################################
#
# HALLWAY CONTROL LIGHTS BASED ON SENSOR AND SCENE GOODNIGHT
#
###########################################################################################
- alias: "Motion Detection - Hallway On Off"
trigger:
platform: state
entity_id: binary_sensor.node_17 # Motion Hallway
condition:
- condition: state
entity_id: switch.mqtt_scene_goodnight
state: "on"
- condition: state
entity_id: switch.mqtt_scene_guests
state: "off"
action:
- service: light.turn_on
data_template:
entity_id: light.hallway
brightness_pct: "{{ 20 if is_state('binary_sensor.node_17', 'on') else 0 }}"
- service_template: >-
{% if (states.binary_sensor.node_17.state) == 'on %} switch.turn_on
{% else %} switch.turn_off
{% endif %}
entity_id: switch.meek_hallway
- service: mqtt.publish
data_template:
topic: "homeassistant/motion/hallway"
payload: "{{ 1 if is_state('binary_sensor.node_17', 'on') else 0 }}"