I have some Zooz Z-Wave power plugs that are connected to my washer and dryer. Get alerted on my phones when they go thru their various cycles. Has been flawless. Just upgraded to version 2202.6.6 from 2202.6.5 and they no longer work. I’ve changed nothing else. Any idea what’s happening? I get the below message in the logs if it helps:
Logger: homeassistant.components.automation.dryer_send_alert_when_dryer_is_finished
Source: helpers/script.py:1718
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 8:13:24 AM (2 occurrences)
Last logged: 8:45:00 AM
[Dryer] Send alert when dryer is finished: Error executing script. Error for call_service at pos 1: Template rendered invalid service:
Know it says invalid service but as mentioned didn’t change anything so thought I’d see if anything rings a bell before I have to dig into it or revert.
I think sharing the script would help visitors to help fix it.
I had some errors regarding a time specification that was a number like 65650 instead of something like 21:00:00 . So I guess some things changed in how the yaml files are interpreted (in my case: how times are interpreted).
It was not easy to identify from the error message as it did not point to the correct line, even after putting my automations.yaml in the configuration.yaml itself.
I can, but it’s going to be a pain. Lot of code across a lot of files. Was hoping there was a general issue that I would need to look at based on that issue but can try to post it to the best of my ability to get it all in here.
Let me start with this. So there are two of them, one for washer and one for dryer. So thinking this is what’s triggering the invalid service:
- id: dryer_alert_finished
alias: "[Dryer] Send alert when dryer is finished"
trigger:
- platform: state
entity_id: sensor.dryer_status
to: Dry
for:
minutes: 1
- platform: state
entity_id: device_tracker.barb_s_iphone_unifi
to: 'home'
for:
minutes: 2
- platform: state
entity_id: device_tracker.john_s_iphone_unifi
to: 'home'
for:
minutes: 2
- platform: time
at: '08:45:00'
condition:
condition: and
conditions:
- condition: time
before: '22:30:00'
after: '06:30:00'
- condition: state
entity_id: group.everyone
state: 'home'
- condition: state
entity_id: input_select.dryer_status
state: Dry
- condition: template
value_template: >
{% if states.automation.dryer_send_alert_when_dryer_is_finished.last_triggered is not none %}
{% if as_timestamp(now()) | int - as_timestamp(states.automation.dryer_send_alert_when_dryer_is_finished.attributes.last_triggered) | int > 1800 %} true {% else %} false
{% endif %}
{% else %}
false
{% endif %}
action:
- service_template: >
{% if (is_state('device_tracker.john_s_iphone_unifi', 'home')) and (is_state('device_tracker.barb_s_iphone_unifi', 'home')) %}
notify.john_and_barb
{% elif is_state('device_tracker.john_s_iphone_unifi', 'home') %}
notify.mobile_app_siphone
{% elif is_state('device_tracker.barb_s_iphone_unifi', 'home') %}
notify.mobile_app_biphone
{% endif %}
data:
message: 'The dryer has finished and is ready to be emptied'
title: 'Dryer'
- service: input_select.select_option
data:
entity_id: input_select.dryer_status
option: Idle
So when the dryer is done and the voltage drops, and someone is home, and it’s not after certain times of the day it texts people that it’s done. Any thoughts? I can pull in more segments but thought I’d see if the above screams any reasons for the
[Dryer] Send alert when dryer is finished: Error executing script. Error for call_service at pos 1: Template rendered invalid service:
It contains an if-elif-elif chain without a final else. If none of the first three tests in the chain are fulfilled, it exits without producing the name of a service call and that’s an error.
Template rendered invalid service:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
your template produced nothing
Apparently, it may have a loophole; the error is clearly complaining that the template produced no value for the service_template option. The only way that can happen is for the entire if-elif-elif chain to be unfulfilled (i.e. each one evaluated to false).
NOTE
If you (the topic author) tested the automation by clicking its Run Actions button, it will skip the triggerandcondition and simply execute action.
You could check if you can use ‘notify.notify’ as a service which allows you to set the targets.
I am not sure this is the right code, it’s just to suggest an alternative.
- service: notify.notify
data:
title: Dryer
message: The dryer has finished and is ready to be emptied
target: >
{% if (is_state('device_tracker.john_s_iphone_unifi', 'home')) and
(is_state('device_tracker.barb_s_iphone_unifi', 'home')) %}
jon barb
{% elif is_state('device_tracker.john_s_iphone_unifi', 'home') %}
mobile_app_siphone
{% elif is_state('device_tracker.barb_s_iphone_unifi', 'home') %}
mobile_app_biphone
{% endif %}
Note probably mentioned this but it worked until recently however that said the error seems to happen when it’s going to successfully trigger alerts to the phones, not if it fails to match an else statement.
It fails to “trigger alerts to the phones” because the template you created doesn’t produce a service call. That’s what the error message is complaining about, it didn’t get a service call.
Why does the template fail to produce a service call? Because each part of the template’s if-elif-elif chain didn’t evaluate to true so the template finished without reporting a result.
Copy-paste the following example into the Template Editor. The result of it is nothing. That’s what’s happening with your template.
{% set x = 'cat' %}
{% if x == 'bat' %}
A
{% elif x == 'hat' %}
B
{% elif x == 'rat' %}
C
{% endif %}
This example reports Z because after confirming it’s neither bat, hat, or cat, it defaults to whatever the else says to do.
{% set x = 'cat' %}
{% if x == 'bat' %}
A
{% elif x == 'hat' %}
B
{% elif x == 'rat' %}
C
{% else %}
Z
{% endif %}
If you were to do that in your template, it’s likely to eliminate the error message (but is more of a workaround than a solution).
- service: >
{% set john_home = is_state('device_tracker.john_s_iphone_unifi', 'home') %}
{% set barb_home = is_state('device_tracker.barb_s_iphone_unifi', 'home') %}
{% if john_home and barb_home %} notify.john_and_barb
{% elif john_home %} notify.mobile_app_siphone
{% elif barb_home %} notify.mobile_app_biphone
{% else %} notify.mobile_app_siphone
{% endif %}
data:
message: 'The dryer has finished and is ready to be emptied'
title: 'Dryer'
Thanks for the info. Still evaluating but this would kind of break the flow no? The expectation is if both john and barb are home and the dryer finishes alert both their phones. If just john is home alert him. If just barb is home alert her. If they are both gone do nothing until one of them comes home and send them an alert. This prevents being at the store and being told the dryer is done and forgetting about it by the time they are home. The example above else statement would send out the notice always to a phone if no one was around correct?
That’s not what the service template you created will do. If both are gone it produces no service call and that causes an error.
The crucial point here is that if the automation’s State Condition is true, meaning group.everyone is home, therefore someone should be home and the service template should report a service call.
However, for some yet unknown reason, State Condition is true yet the service call’s template doesn’t see either of the two device-trackers are home.
Right. It’s not meant to be a proper solution to your problem, only to demonstrate that if you were to do that it would prevent the error message from occurring. The real solution is to figure out why group.everyone reports home yet the service template apparently doesn’t see either device_tracker as home.
It’s behaving like if device_tracker.jiphone was home but device_tracker.john_s_iphone_unifi is not_home. That’s sufficient to set the state of group.everyone to home but would not be good for the service template because it’s specifically checking device_tracker.john_s_iphone_unifi.