KCYeoh
(Yeoh)
September 30, 2020, 2:20am
1
Hi, I want to be able to retrieve some attributes abd create a sensor for it so that i can put them on the lovelace UI. For example, showing the distance of waze travel route and showing the battery level of phones that installed withe companion apps.
I don’t know how to do it. Is anyone here mind show me some example?
Thanks in advance.
tom_l
September 30, 2020, 4:15am
2
Here is a sensor that interrogates one of my Yamaha amplifiers and records the settings as attributes. Under it are template sensors that convert some of the attributes to separate sensors:
- platform: rest
name: Lounge Amp
resource: http://10.1.1.16/YamahaExtendedControl/v1/main/getStatus
value_template: "{{ value_json.power }}"
json_attributes:
- adaptive_drc
- adaptive_dsp_level
- dialogue_level
- dialogue_lift
- dts_dialogue_control
- enhancer
- extra_bass
- surr_decoder_type
- sound_program
- subwoofer_volume
- platform: template
sensors:
lounge_dialogue_lift:
friendly_name: Dialogue Lift
value_template: "{{ state_attr('sensor.lounge_amp', 'dialogue_lift')|float / 2 }}"
lounge_dialogue_level:
friendly_name: Dialogue Level
value_template: "{{ state_attr('sensor.lounge_amp', 'dialogue_level')|int }}"
lounge_surround_decoder_type:
friendly_name: Surround Decoder
value_template: "{{ state_attr('sensor.lounge_amp', 'surr_decoder_type')|replace('_', ' ')|title|replace('Dts', 'DTS') }}"
lounge_sound_program:
friendly_name: Sound Program
value_template: "{{ state_attr('sensor.lounge_amp', 'sound_program')|replace('_', ' ')|title }}"
lounge_subwoofer_level:
friendly_name: Subwoofer Level
value_template: "{{ state_attr('sensor.lounge_amp', 'subwoofer_volume')|float / 2 }}"
Frank_R
(Frank)
September 30, 2020, 5:15am
3
If it’s just for displaying in Lovelace I sometimes use a custom card that can show attribute value right away. No need for template sensors.
For exapmle:
tom_l
September 30, 2020, 5:54am
4
Actually, if all you want is Lovelace display of the attribute, the core entities card supports attributes now too.