pomah
(roman)
March 11, 2023, 8:50pm
1
Hi, I have a small issue with my latest automation, I want to make the code abit better and easier to follow so I want to use the “trigger_id” as part of the names and messages I send, se code below:
alias: INFO Pusa Mini+
description: ""
trigger:
- platform: state
entity_id:
- sensor.prusalink_f9ccccf4b97be7799c1e605b96942571_printer_state
from: printing
to: idle
for:
hours: 0
minutes: 0
seconds: 10
id: Done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 9.5
below: 11
id: "10"
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 89.5
below: 91
id: "90"
condition: []
action:
- if:
- condition: trigger
id: "10"
then:
- service: camera.snapshot
data:
filename: /config/www/cctv/{{ trigger.id }}.jpg
target:
entity_id: camera.my_camera
- service: notify.mobile_app_
data:
message: {{ trigger.id }}% done
title: Prusa Mini+
data:
image: www.mydns.com/local/cctv/{{ trigger.id}}.jpg
- if:
- condition: trigger
id: "90"
then:
- service: camera.snapshot
data:
filename: /config/www/cctv/{{ trigger.id }}.jpg
target:
entity_id: camera.my_camera
- service: notify.mobile_app_
data:
message: {{ trigger.id }}% done
title: Prusa Mini+
data:
image: www.mydns.com/local/cctv/{{ trigger.id}}.jpg
- if:
- condition: trigger
id: Done
then:
- service: notify.mobile_app_
data:
message: Print done!
title: Prusa Mini+
mode: single
But I cant figure out who to syntax it correctly, any ideas?
Since the action sequences for both the “10” and “90” triggers are essentially the same, with the templating filling in the desired information, you can collapse those two into a single stanza.
Using a Choose Action
alias: INFO Pusa Mini+
description: ""
trigger:
- platform: state
entity_id:
- sensor.prusalink_f9ccccf4b97be7799c1e605b96942571_printer_state
from: printing
to: idle
for:
hours: 0
minutes: 0
seconds: 10
id: Done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 9.5
below: 11
id: "10"
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 89.5
below: 91
id: "90"
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: Done
sequence:
- service: notify.mobile_app_
data:
message: Print done!
title: Prusa Mini+
default:
- service: camera.snapshot
data:
filename: "/config/www/cctv/{{ trigger.id }}.jpg"
target:
entity_id: camera.my_camera
- service: notify.mobile_app_
data:
message: "{{ trigger.id }}% done"
title: Prusa Mini+
data:
image: "www.mydns.com/local/cctv/{{ trigger.id}}.jpg"
mode: single
Equivalent action section, but using If/Then Action
action:
- if:
- condition: trigger
id: Done
then:
- service: notify.mobile_app_
data:
message: Print done!
title: Prusa Mini+
else:
- service: camera.snapshot
data:
filename: "/config/www/cctv/{{ trigger.id }}.jpg"
target:
entity_id: camera.my_camera
- service: notify.mobile_app_
data:
message: "{{ trigger.id }}% done"
title: Prusa Mini+
data:
image: "www.mydns.com/local/cctv/{{ trigger.id}}.jpg"
mode: single
1 Like
pomah
(roman)
March 20, 2023, 4:50pm
4
Hi I figured the same after reading your first post and the final result looks like this:
alias: INFO Prusa Mini+ v2
description: ""
trigger:
- platform: state
entity_id:
- sensor.prusalink_f9ccccf4b97be7799c1e605b96942571_printer_state
from: printing
to: idle
for:
hours: 0
minutes: 0
seconds: 5
id: Done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 9.5
below: 11
id: 10% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 19.5
below: 21
id: 20% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 29.5
below: 31
id: 30% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 39.5
below: 41
id: 40% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 49.5
below: 51
id: 50% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 59.5
below: 61
id: 60% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 69.5
below: 71
id: 70% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 79.5
below: 81
id: 80% done
- platform: numeric_state
entity_id: sensor.progress
for:
hours: 0
minutes: 0
seconds: 5
above: 89.5
below: 91
id: 90% done
condition: []
action:
- service: camera.snapshot
data:
filename: " /config/www/cctv/prusa.jpg"
target:
entity_id: camera.prusa_cam
- service: notify.mobile_app_
data:
data: /local/cctv/prusa.jpg
title: Prusa Mini+
message: "{{ trigger.id }}"
mode: single
Another option:
trigger:
- platform: state
entity_id:
- sensor.prusalink_f9ccccf4b97be7799c1e605b96942571_printer_state
from: printing
to: idle
for: "00:00:05"
variables:
message: "Done"
- platform: template
value_template: >
{% set x = states('sensor.progress') | float(0) %}
{{ (1 >= (x % 10) or (x % 10) >= 9.5) and ( 90 > x > 9 ) }}
for: "00:00:05"
variables:
percentile: "{{ states('sensor.progress') | round(-1) | int }}"
message: "{{ percentile }}% done"
condition: []
action:
- service: camera.snapshot
data:
filename: " /config/www/cctv/prusa.jpg"
target:
entity_id: camera.prusa_cam
- service: notify.mobile_app_
data:
data: /local/cctv/prusa.jpg
title: Prusa Mini+
message: "{{ message }}"
mode: single