unlikes
January 25, 2020, 12:58pm
1
Hello,
I encounter a problem to get a specific attribute (round_trip_time_avg) from a binary sensor.
Here is my configuration :
binary_sensor:
platform: ping
name: Nuc01
host: 192.168.5.5
count: 4
scan_interval: 60
platform: template
sensors:
ping_nuc01:
device_class: connectivity
entity_id:
- binary_sensor.nuc01
value_template: “{{ state_attr(‘binary_sensor.nuc01’, ‘round_trip_time_avg’) }}”
After restarting HA, I check in dev tool the state for the entity binary_sensor.ping_nuc01, The indicated state is “Off” which is not the expected result.
Can you tell me where is my mistake here ?
A binary sensor can only be on or off (binary). You need to use a regular (analog) template sensor to display that attribute. That template sensor will go under sensor:
in your config.
1 Like
Hi Tediore,
Thanks for the tips, it seems logical by the way :).
I got the expected result with this configuration
#------MONITORING SECTION------#
binary_sensor:
platform: ping
name: Nuc01
host: 192.168.5.5
count: 4
scan_interval: 60 #30 secondes
#–SENSOR SECTION–#
sensor:
#Ping sensor Latency
platform: template
sensors:
ms_nuc01:
friendly_name: “Latence Nuc01”
unit_of_measurement: ‘ms’
value_template: “{{ state_attr(‘binary_sensor.nuc01’, ‘round_trip_time_avg’) }}”
By the way, when asking questions like this in the future, be sure to format your code properly. Use three backticks (```) above and below the code, otherwise we can’t see if there are indentation issues
@Tediore
Would you be so kind to assist me, I cannot get it to work and even worse I do not get any error.
The check configuration tool just keeps looping without presenting me with an error.
The binary sensor ping works without the template.
binary_sensor:
- platform: ping
host: 8.8.8.8
name: "google ping"
count: 5
scan_interval: 30
- platform: template
sensors:
google_ping_time_avg:
friendly_name: "google ping time avg"
unit_of_measurement: "ms"
value_template: "{{ state_attr('binary_sensor.google_ping', 'round_trip_time_avg' }}"
The indentation for the template sensor is not correct:
- platform: template
sensors:
google_ping_time_avg:
friendly_name: "google ping time avg"
unit_of_measurement: "ms"
value_template: "{{ state_attr('binary_sensor.google_ping', 'round_trip_time_avg' }}"
koying
(Chris B)
October 14, 2021, 9:38am
7
You’re missing a closing parenthesis: ...'round_trip_time_avg') }}"
Keep in mind you have the Developer Tools - Template to test your templates.
Awesome everyone. It now works.
configuration.yaml
binary_sensor:
- platform: ping
host: 8.8.8.8
name: "google ping"
count: 5
scan_interval: 30
sensor:
- platform: template
sensors:
google_ping_time_avg:
friendly_name: "google ping time avg"
unit_of_measurement: "ms"
value_template: "{{ state_attr('binary_sensor.google_ping', 'round_trip_time_avg') }}"
google_ping_time_max:
friendly_name: "google ping time max"
unit_of_measurement: "ms"
value_template: "{{ state_attr('binary_sensor.google_ping', 'round_trip_time_max') }}"
google_ping_time_min:
friendly_name: "google ping time min"
unit_of_measurement: "ms"
value_template: "{{ state_attr('binary_sensor.google_ping', 'round_trip_time_min') }}"