bazcurtis
(Michael Curtis)
March 3, 2023, 5:38pm
1
I have set up the following binary sensor. It is checking to see if I am importing from the grid or not
template:
- binary_sensor:
- name: On Grid
state: "{{ states('sensor.lux_power_from_grid_to_house_live') | int(-1) > 0 }}"
I then wrote this automation to send me a message, but it is not triggering. What have I missed?
alias: Grid Status
description: Grid Status
trigger:
- platform: template
value_template: "{{ states('On Grid')| int(0) > 0 }}"
condition:
- condition: time
after: "08:00:00"
before: "21:00:00"
action:
- service: notify.notify
data:
message: |
{% if is_state('sensor.lux_power_from_grid_to_house_live', 'off' ) %}
Off Grid
{% else %}
On grid using {{ states("sensor.lux_power_from_grid_to_house_live") }} watts
{% endif %}
title: Grid Status
mode: single
dproffer
(David Proffer)
March 3, 2023, 6:11pm
2
I’m not sure if your logic to check a binary sensor will work or not, however I use something like below in my automations for binary sensors:
- alias: International Space Station 10 Minute Pass Warning
trigger:
- platform: state
entity_id: binary_sensor.international_space_station_iss_10_minute_pass_warning
to: 'on'
Good hunting!
kbrown01
(Kbrown01)
March 3, 2023, 6:14pm
3
bazcurtis:
states('On Grid')
That is not a sensor.
states('binary_sensor.on_grid')
Developer tools are your friend. You should use them first to write your templates:
123
(Taras)
March 3, 2023, 6:30pm
4
alias: Grid Status
description: Grid Status
trigger:
- platform: state
entity_id: binary_sensor.on_grid
condition:
- condition: time
after: "08:00:00"
before: "21:00:00"
action:
- service: notify.notify
data:
message: |
{% if trigger.to_state.state == 'off' %}
Off Grid
{% else %}
On grid using {{ states("sensor.lux_power_from_grid_to_house_live") }} watts
{% endif %}
title: Grid Status
mode: single
bazcurtis
(Michael Curtis)
March 4, 2023, 9:43am
5
That is a very good tip. Thank you. I used Developer Tools to write the template and used states to check it, but never thought to use the Developer Tools for the automation syntax
bazcurtis
(Michael Curtis)
March 4, 2023, 9:43am
6
Thank you. I have added that. I will see if it triggers today. Not sure if the battery will drain enough.