andrewjswan
(Andrew J.Swan)
September 18, 2021, 6:04pm
1
I try make binary sensor from trigger, but binary sensor not work:
Example in Documentation: Template - Home Assistant
Code:
template:
- trigger:
- platform: state
entity_id: sensor.remote_event_a4ek00_button
- binary_sensor:
- name: "Yeelight Childroom Button Click"
icon: mdi:gesture-tap-button
auto_off: 1
state: "true"
- trigger:
- platform: state
entity_id: binary_sensor.yeelight_childroom_button_click
- sensor:
- name: "Yeelight Childroom Button"
icon: mdi:gesture-double-tap
state: >
{%- if states('binary_sensor.yeelight_childroom_button_click') -%}
{{ states('sensor.remote_event_a4ek00_button_click_type') }}
{%- else -%}
no press
{%- endif -%}
Result:
after 1 minutes binary sensor is On
Can you explain what it is you are trying to do?
tom_l
September 19, 2021, 12:41am
3
Check the docs again. There is no dash in front of sensor:
or binary_sensor:
only in front of trigger:
.
You want to make a list of triggered sensors , not a list of triggers and sensors .
template:
- trigger:
- platform: state
entity_id: sensor.remote_event_a4ek00_button
binary_sensor:
- name: "Yeelight Childroom Button Click"
icon: mdi:gesture-tap-button
auto_off: 1
state: "true"
- trigger:
- platform: state
entity_id: binary_sensor.yeelight_childroom_button_click
sensor:
- name: "Yeelight Childroom Button"
icon: mdi:gesture-double-tap
state: >
{%- if states('binary_sensor.yeelight_childroom_button_click') -%}
{{ states('sensor.remote_event_a4ek00_button_click_type') }}
{%- else -%}
no press
{%- endif -%}
If you want to add some state based sensors as well, then you can add the dash in front of sensor:
or binary_sensor:
Then your list will contain triggered sensors, and sensors.
template:
# triggered sensors
- trigger:
- platform: state
entity_id: sensor.remote_event_a4ek00_button
binary_sensor:
- name: "Yeelight Childroom Button Click"
icon: mdi:gesture-tap-button
auto_off: 1
state: "true"
- trigger:
- platform: state
entity_id: binary_sensor.yeelight_childroom_button_click
sensor:
- name: "Yeelight Childroom Button"
icon: mdi:gesture-double-tap
state: >
{%- if states('binary_sensor.yeelight_childroom_button_click') -%}
{{ states('sensor.remote_event_a4ek00_button_click_type') }}
{%- else -%}
no press
{%- endif -%}
# state based sensors (examples)
- sensor:
- name: "Transmission Down Speed"
unit_of_measurement: "kB/s"
state: "{{ states('sensor.transmission_down_speed')|float * 1024 }}"
- name: "Transmission Up Speed"
unit_of_measurement: "kB/s"
state: "{{ states('sensor.transmission_up_speed')|float * 1024 }}"
- binary_sensor:
- name: "Washing Machine"
delay_off:
minutes: 5
state: >
{{ states('sensor.washing_machine_power')|float > 0 }}
1 Like
andrewjswan
(Andrew J.Swan)
September 19, 2021, 6:23am
4
I went a long way, from the sensor to the template, and then to the template trigger. So I came up with something superfluous. And there is no errors when config check. Now I removed it, I will check it. Thanks.
andrewjswan
(Andrew J.Swan)
September 19, 2021, 6:24am
5
Automatic status change of button press status.