If unit_system: imperial, cannot get any sensors in celsius

Likewise, if unit_system: metric, then cannot get fahrenheit sensors. Such is the case at the moment.

Here are two of my sensors:

  • platform: template
    sensors:
    thermostat_current_temp:
    value_template: ‘{{ states.climate.thermostat.attributes.current_temperature }}’

  • platform: template
    sensors:
    thermostat_current_temp_f:
    unit_of_measurement: ‘°F’
    value_template: “{{ ((float(states.climate.thermostat.attributes.current_temperature) * 9 / 5 ) + 32) | round(1) }}”

Here are the entiities:
climate.thermostat cool current_temperature: 22.2
min_temp: 7
max_temp: 35
temperature: 22.2
target_temp_high: null
target_temp_low: null
fan_mode: auto
fan_list: on,auto
operation_mode: cool
operation_list: off,heat,cool,auto
away_mode: off
aux_heat: off
unit_of_measurement: °F
friendly_name: Thermostat
supported_features: 3271
custom_ui_state_card: state-card-custom-ui
state_card_mode: break-slider-toggle
show_last_changed: true

*** unit is F, but data is stored as C

sensor.thermostat_current_temp 22.2
friendly_name: thermostat_current_temp
custom_ui_state_card: state-card-custom-ui

sensor.thermostat_current_temp_f 22.2
unit_of_measurement: °C
friendly_name: thermostat_current_temp_f
custom_ui_state_card: state-card-custom-ui

*** unit of measurement wrong, after value-template applied it appears that the data was reconverted to C for storage.

I have been experimenting for hours and can find no way to have both C and F sensors. Yes, I’ve used Customize with no change in end data.

This issue seems to have been reported back in version 35. Is it not fixed, or has it reemerged in 67?

I am desperate for any help.

because your config is wrong, it should look like this:

- platform: template
  sensors:
    thermostat_current_temp:
      unit_of_measurement: '°C'
      value_template: '{{ states.climate.thermostat.attributes.current_temperature }}'
    thermostat_current_temp_f:
      unit_of_measurement: '°F'
      value_template: '{{ ((float(states.climate.thermostat.attributes.current_temperature) * 9 / 5 ) + 32) | round(1) }}'

When you use platform:template twice, the second one overwrites the first. Put both into the same platform. That’s why the section is called ‘sensors’ and not ‘sensor’.

Also, to be safe, you should probably swap to states_attr() so the value has a default when it cannot communicate to the device, take a look at the templating page:

Thank you Petro.

Do I understand you correctly. Two platform: template entries, one defining sensor A, and one defining sensor B, will result in only one entity (because the second overlays the first). But, one platform: template entry that includes two sensors will result in two entities?

Yes, I’m not sure which one will override, the first or second. One will override the others. But treat the whole section as a container for all your template sensors. I have like 14 in mine:

  - platform: template
    sensors:
      main_door_hindge: # MAIN DOOR SENSOR #
        value_template: >
          {% if is_state('sensor.main_door_t_access_control_9_9', '23') %}
            closed
          {% elif is_state('sensor.main_door_t_access_control_9_9', '22') %}
            open
          {% else %}
            closed
          {% endif %}
        friendly_name: Main Door Status
      main_door_battery: # MAIN DOOR BATTERY #
        value_template: >
          {% if states('sensor.main_door_t_access_control_9_9') in ['22','23'] %}
            {{ states.sensor.main_door_t_access_control_9_9.attributes.battery_level }}
          {% else %}
            100
          {% endif %}
        friendly_name: Main Door Battery
        unit_of_measurement: "%"
      entry_door_hindge: # GARAGE ENTRY DOOR SENSOR #
        value_template: >
          {% if is_state('sensor.entry_door_t_access_control_18_9', '23') %}
            closed
          {% elif is_state('sensor.entry_door_t_access_control_18_9', '22') %}
            open
          {% else %}
            closed
          {% endif %}
        friendly_name: Garage Entry Door Status
      entry_door_battery: # GARAGE ENTRY DOOR BATTERY #
        value_template: >
          {% if states('sensor.entry_door_t_access_control_18_9') in ['22','23'] %}
            {{ states.sensor.entry_door_t_access_control_18_9.attributes.battery_level }}
          {% else %}
            100
          {% endif %}
        friendly_name: Garage Entry Door Battery
        unit_of_measurement: "%"
      hallway_motion_battery:
        value_template: >
          {% if states('states.sensor.hallway_ms_burglar_32_10') in ['0','3','8'] %}
            {{ states.sensor.hallway_ms_temperature_32_1.attributes.battery_level }}
          {% else %}
            100
          {% endif %}
        friendly_name: Motion Sensor Battery
        unit_of_measurement: "%"
      harmony_activity:
        value_template: >
          {% if is_state("remote.living_room", 'on') %}
            {{ states.remote.living_room.attributes.current_activity }}
          {% else %}
            PowerOff
          {% endif %}
1 Like