Create 3 state templated text sensor to describe humidity

Hi,

I’m trying to make a 3 state sensor to describe humidity in words, such as “dry”, “comfortable” and " humid" which i can then use to show on the lovelace ui and also trigger automations more intuitivly.

is it possible?

thanks.

You can use the text template sensor.

I started to type out an example on my phone but it started to get messy quickly :roll_eyes:

Success:

text_sensor:
  - platform: template
    name: ${devicename} Humidity Text
    lambda: |-
      if (id(living_room_humidity).state > 65) {
        return {"Humid"};
      } else if (id(living_room_humidity).state < 40) {
        return {"Dry"};
      } else {
        return {"Comfortable"};
      }
    update_interval: 60s

took me a while to understand that it is just a plain c++ snippet.

Thanks for that. I was looking for Cardinal wind direction from a 0-360 degree wind direction signal.
The code below got it done for me, just in case someone needs it.

# Cardinal Wind direction
text_sensor:
  - platform: template
    name: Cardinal Wind Direction
    lambda: |-
      if (id(WindDir).state < 22.5 || id(WindDir).state >= 337.5) {
        return {"North"};
      } else if (id(WindDir).state >= 22.5 && id(WindDir).state < 67.5) {
        return {"North East"};
      } else if (id(WindDir).state >= 67.5 && id(WindDir).state < 112.5) {
        return {"East"};
      } else if (id(WindDir).state >= 112.5 && id(WindDir).state < 157.5) {
        return {"South East"};
      } else if (id(WindDir).state >= 157.5 && id(WindDir).state < 202.5) {
        return {"South"};
      } else if (id(WindDir).state >= 202.5 && id(WindDir).state < 247.5) {
        return {"South West"};
      } else if (id(WindDir).state >= 247.5 && id(WindDir).state < 292.5) {
        return {"West"};
      } else if (id(WindDir).state >= 292.5 && id(WindDir).state < 337.5) {
        return {"North West"};
      } else {
        return {"Something is not Right..."};
      }
    update_interval: 1s
} else { return {"Something is not Right..."};

Great work!

huh?
maybe

} else return {"Something is not Right..."};

if it’s C++ code. Btw, do we need these {} around string here?

I unintentionally tested it. I accidentally used && for the north position.

It’s handy to keep in there for testing purposes.

I just like that you allowed for errors with a helpful message!