First time user- need a little help

Hi,

I know this is probably very obvious but I can’t work it out!

I want to make my temperature sensor have a state of on when above 22 degrees.

I have it working on the main page via this code:

#AM2302 Sensor
sensor:
  platform: dht
  sensor: AM2302
  pin: 4
  scan_interval: 10
  monitored_conditions:
    - temperature
    - humidity

I also have a blueprint for nagging notifications that I’m trying to integrate it in to. What I don’t know is how to code it. Help!

That’s not the way it works, the temp sensor will give you a numeric value. From there you could create another sensor that would read on/off depending on the values you set. then that sensor could be used with the blueprint.

template:
  - binary_sensor:
      - name: "temp22"
        device_class: temperature
        state: >
          {{ states('sensor.am2302')|float > 22 }}
  • I am guessing that the original sensor’s name is sensor.am2302 since there is no name configured

Typically you would not create another sensor for this, automations can be triggered by thresholds.

1 Like

Excellent, thanks. This sorted it :slight_smile:

I just learned there’s a change and figured I’d pass it on since the above is going to give an error in the logs. You have to add a default value for sensor.am2302.

</s> <s>{{ states('sensor.am2302')|float("unavailable") > 22 }}</s> <s>

This will return unavailable if there is a problem with sensor.am2302.

edit disregard.

Are you sure the default is correct? I thought the default value has to be of the same type than the filter it gets used by. :slight_smile:

In this case

{{ states('sensor.am2302')|float(0) > 22 }}

lol yeah it passed the config editor but I know it’s wrong. I’m trying to work it out right now.

Honestly, I have no idea :rofl: I tried to find an answer for myself a few days ago, but couldn’t find anything useful in the documentation and lost motivation… :wink: :rofl:

For now I have set the defaults to a value according to the type and to the threshold, in this case I’d do it like this:

{{ states('sensor.am2302')|float(22) > 22 }}

The problem is that you’ll only notice it’s not working because it’s stuck in one position for a period of time.

@Tap1 you’ll need to use the above example. You will have to choose a number above or below depending on what you want the default value to be, on/off.

Thanks all, I’ve now got this:

template:
  - binary_sensor:
      - name: "Bolier Temp Binary"
        device_class: heat
        state: >
          {{ states('sensor.dht_sensor_temperature')|float(22) > 22 }}