Create sensors based on entities attributes

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.

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 }}"

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:

Actually, if all you want is Lovelace display of the attribute, the core entities card supports attributes now too.