Template to create sensor from state data

Hi,

I have been trying to create a sensor using a template. But i can’t get it to work.

I have an climate.bathroom entity that looks like this:

hvac_modes:
  - 'off'
  - heat
min_temp: 5
max_temp: 35
preset_modes:
  - none
  - temporary
  - permanent
current_temperature: 19.5
temperature: 18.5
preset_mode: none
status:
  setpoints:
    this_sp_from: '2020-12-08T07:30:00+01:00'
    this_sp_temp: 18.5
    next_sp_from: '2020-12-08T18:00:00+01:00'
    next_sp_temp: 20
  zone_id: '1192843'
  active_faults: []
  setpoint_status:
    target_heat_temperature: 18.5
    setpoint_mode: FollowSchedule
  temperature_status:
[u]    temperature: 19.5[/u]
    is_available: true
friendly_name: Badkamer
icon: 'mdi:radiator'
supported_features: 17

I want to create a sensor from the status: temperature_status: temperature.

I don’t know and can’t find how to format the template. This is what i got so far, but that doesn’t work and I did find some forum topics to use a . after the ), but couldn’t find how this would work in this case.

sensor:
  - platform: template
    sensors:
      temp_badkamer:
        friendly_name: "Temperatuur Badkamer"
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('climate.badkamer.status.temperature_status', 'temperature') }}"

Hope it is has an easy solution :slight_smile:

I think a solution similar to this one should work for you as well.

sensor:
  - platform: template
    sensors:
      temp_badkamer:
        friendly_name: "Temperatuur Badkamer"
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('climate.bathroom', 'status')['temperature_status']['temperature'] }}"
1 Like