Unit_of_measurement template - Configuration

Hi,

i need help with a template that i’m trying to make:

this is the template:

      ac_on:
        friendly_name: AC
        unit_of_measurement: 'On'
        value_template: >
          {% set total = 0 %}

          {% if is_state('climate.mzgn_slvn', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
          {% if is_state('climate.mzgn_khdr_shynh', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
            
          {{total}}

So far so good, the only catch that i have is that i need is 2 more unit of measurement in to the same template beside the ‘On’ , the 2 are:
‘Cool’
‘Heat’

3 total.

Can it be done?

No, you can’t change units of measurement on the fly like that.
What you can do is create a sensor that displays your 3 different text values depending on the state of another entity

@Mutt Thank you!

i created 2 more sensors, total of 3:
sensor.ac_on
sensor.ac_on2
sensor.ac_on3

can you please show me, how can i a sensor that display the 3 text values depending on the state of another entity, like you suggested.

thank you

No, you don’t need 3 sensors you only need 1
What are your templates for generating your 3 sensors above ?
I assume that you are just using this for display purposes as you seem to have the ability to generate sensors on the 3 states ?
Are these mutually exclusive, i.e. can only 1 of these be on at any one time ?
If not is there a pattern ?

the template is for determine if the ac is on,
basically i have 3 modes: on, heat, cool
Than i present the entity as button in order to determine if the ac is on or not.

this is the sensor:
image
if the state of the ac is on, the state number will change to 1 as it should.
but if i turning on the ac from hassio to the state Cool, it will not change. it will stay 0 because i’m checking the unit_of_measurement: ‘On’ and not cool and heat.

forgot to mention that i have 3 ac’s

Thank you,

Sorry, I think I have gotten the wrong end of the stick (I don’t understand you)
Are you trying to switch the Air Conditioner to one of 3 states : ‘on’, ‘cool’ and ‘heat’ ?
What about ‘off’ ?
Or are you trying to display what status the AC is currently in : On, Off, Heat, Cool ???
What entity is exposed into HA ?
When you query its states in the “developer tools” - “template” editor, what do you get ?
For example : -
When I ask to resolve - “{{ states.media_player.pi_nas01 }}”
(This is a media player entity on my system)
I get : -
“<template state media_player.pi_nas01=playing; volume_level=0.2, is_volume_muted=False, media_content_type=music, media_duration=334, media_position=93, media_position_updated_at=2019-10-07T14:29:42.041516+01:00, media_title=How Big, How Blue, How Beautiful, media_artist=Florence + The Machine, media_album_name=How Big, How Blue, How Beautiful, friendly_name=Pi-NAS01, entity_picture=/api/media_player_proxy/media_player.pi_nas01?token=5b3320d10be894f3400525b5a3bb620acf9566867585c6ef5bba494f8f1b6b4c&cache=90a17d8c8ef37274, supported_features=58303 @ 2019-10-07T09:27:13.051154+01:00>”

let me simply what i need, i need a sensor that can Calculate the state from the three sensors:
sensor.ac_on
sensor.ac_on2
sensor.ac_on3

a simple Calculation operation is it possible?
basically i want to able to display the total number from the three sensor.

OK, so if only : - ac_on is on then - on
If ac_on and ac_on2 is on then - cool
And if all 3 on then - heat
Yes.???

i have 3 ac’s at home, let say ac1 is state is = on (+1), ac2= off (0), ac3= heat (+1)

Than from the three ac’s that i have only 2 is working, than i would be able to know how many ac’s are working .

Thanks !

heat = on
cool = on
on = on

i’m only interesting to know how many ac’s are working.

the sensors that i created basically will return 1 for each entity that the state will be on/heat/cool

If you have three air-conditioners (equipment designed exclusively for cooling) why would their state ever indicate heat?

They can used for cool and heat, in the winter we are changing the state to heat

OK, so not an air-conditioner but a heat pump?

Air conditioner that using to cool and heat

I’ll take you’re word for that. In North America, the word ‘air-conditoner’ (AC) implies it is only capable of cooling whereas ‘heat pump’ can do both (cool and heat).

This template selects all climate entities whose state is not off, counts and reports the result.

{{ states.climate | selectattr('state', 'ne', 'off') | list | count }}

It can be used to create a Template Sensor:

  - platform: template
    sensors:
      ac_on:
        friendly_name: 'AC units on'
        entity_id:
          - climate.mzgn_slvn
          - climate.mzgn_khdr_shynh
          - climate.third_ac
       value_template: >-
          {{ states.climate | selectattr('state', 'ne', 'off') | list | count }}
1 Like

Another neat solution, I hadn’t appreciated the multiple states and when I did the intended template would have been very large.

Technically an air conditioner is a heat pump too.
Normally the smaller units just have a fan heater built in.
Otherwise they are fairly standard (compressor, expansion vessel, fan and piping between)
Here is an example : -

https://www.carltonsales.co.uk/mitsubishi-heavy-industries-srk35zsp-s-wall-mounted-standard-inverter-air-conditioning-system.html?utm_source=google_shopping&m=Abstract&gclid=CjwKCAjwxOvsBRAjEiwAuY7L8pAfH_GQOuHfATK9v16dAFrpeJIqoq27gu4uzi8oBWWbz0nNlX4vFBoCCysQAvD_BwE

Technically speaking but, at least in North America, not practically if it doesn’t produce heat inside the dwelling. Like I said, a heat pump that doesn’t produce heat (inside) is (in NA) called an air-conditioner.

Interesting to learn that this distinction isn’t used globally and the term ‘air-conditioner’ can mean the device also produces heat. If you purchase an air-conditioner in North America, you do so with no preconceptions of it being able to heat (examples of central air-conditioning units designed to provide cooling for a central forced-air HVAC system).

It’s not universal and the units are not of high capacity and you have to search hard for them. They are a bit of a half way solution though ideal for small rooms where the convenience of having two devices in one (high on a wall) is a major boon.
If you just said “Air Conditioner”, most people would assume it would only be capable of cooling.

And both technically and practically anything that takes heat from point A to point B is a heat pump, no matter the direction. Merely because your naming convention does not follow the actual science does not mean the principle does not apply. We’ve already covered that US names are not universally adopted.

Edit: Europe is just as guilty, heat pump is usually assumed to be ground heat recovery

@123 Thank you !!! it’s working !

just from curiosity, if one of the entities wasn’t a climate instead it was a switch, how would you write the script?

  - platform: template
    sensors:
      ac_on:
        friendly_name: 'AC units on'
        entity_id:
          - switch.test
          - climate.mzgn_khdr_shynh
          - climate.third_ac
       value_template: >-
          {{ states.climate | selectattr('state', 'ne', 'off') | list | count }}

Thanks

1 Like

He has a point and given that thermostats are part of the climate domain, if one of them happens to be ‘on’…?

  - platform: template
    sensors:
      ac_on:
        friendly_name: 'AC units on'
        entity_id:
          - switch.test
          - climate.mzgn_khdr_shynh
          - climate.third_ac
       value_template: >-
          {{ expand('switch.test', 'climate.mzgn_khdr_shynh', 'climate.third_ac') | selectattr('state', 'ne', 'off') | list | count }}