I am new to HA and running it on an Ubuntu machine at home and trying to get hands on with automation. So used the automation editor to create a simple automation on Brother’s printer and create a notification if the page counter exceeds 1,000, the counter is currently at 1,100 so notification should pop-up.
I followed following steps:
Step-1:
After completing these steps, the automation is not getting saved nor am I getting any error so not sure if I am doing something wrong or how to correct it.
Yes, pressing the orange button is not doing anything. At first I got a YAML error due to a typo in Actions tags. So based on your suggestion I simplified my example even further and deleted Condition and modified triggers as:
But still getting no error but unable to save automation. I also played around with variations for "for: field using values such as “00:00:05” but still cannot save the automation.
Thanks @123. I finally got it working and had to tweak a lot of things:
- alias: "Printer Test Automation"
trigger:
- platform: state
entity_id: sensor.mfc_j485dw_page_counter
action:
- choose:
# IF page cpunter is more than 1,000
- conditions:
- condition: template
value_template: "{{ sensor.mfc_j485dw_page_counter > 1000 }}"
sequence:
- service: persistent_notification.create
data:
title: "Printer has printed more than 1,000 pages"
message: "Need to get the printer serviced"
# ELSE (i.e. page counter is less than 1,000)
default:
- service: persistent_notification.create
data:
title: "Printer has printed less than 1,000 pages"
message: "Your printer is in good health"
- alias: "Printer Test Automation"
trigger:
- platform: state
entity_id: sensor.mfc_j485dw_page_counter
action:
- service: persistent_notification.create
data_template:
title: >
Printer has printed {{ 'more' if trigger.to_state.state|int > 1000 else 'less' }} than 1,000 pages
message: >
{{ 'Need to get the printer serviced' if trigger.to_state.state|int > 1000 else 'Your printer is in good health' }}
If you triggered it manually, that skips the automation’s trigger (and condition if it has one) and executes the action only. When it does that, the Trigger State Object is undefined because the automation’s trigger never executed.
From the documentation:
Be aware that if you reference a trigger state object in templates of automation action , attempting to test that automation by calling the automation.trigger service or by clicking EXECUTE in the More Info box for the automation will not work. This is because the trigger state object doesn’t exist in those contexts