(Solved) Binary sensor > than with a minimum

Hi All,

I try create a automation to turn off a z-wave switch if the temperature of my 3d printer bed or nozzle gets 5 degrees higher then the target temperature.

When printer is cold or I turned it on the target values are 0 and actual values are around 20-25 degrees (room temperature). That means the calculation is always in rising state and the sensors turn on.

How can I change this that the target temperature gets a minimum value of 40 degrees even its actual 0?

- binary_sensor:
    - name: "3D Printer bed temp rising"
      unique_id: "4548ba6b-a249-485c-9913-664728ec0982"
      state: >-
        {% set value = (states('sensor.ender_3_bed_temperature') | int(default=0) | round(1) - states('sensor.ender_3_bed_target') | int(default=0) | round(1) ) > 5 %}
        {{ value }}

- binary_sensor:
    - name: "3D Printer extruder temp rising"
      unique_id: "1072442e-a309-40ae-a960-81c8c29a86b8"
      state: >-
        {% set value = (states('sensor.ender_3_extruder_temperature') | int(default=0) | round(1) - states('sensor.ender_3_extruder_target') | int(default=0) | round(1) ) > 5 %}
        {{ value }}
      state: >-
        {{ (states('sensor.ender_3_bed_temperature')|int(0) -
            max(40, states('sensor.ender_3_bed_target')|int(0))) > 5 }}

and similarly for the other one.


  • You don’t need to set a value and then output it, you can do it in one step.
  • No point round-ing here: you don’t see the values
  • int(0) is the same as int(default=0)
  • max(40, x) will give you x or 40 if x is lower than 40.
1 Like

Haha… that whole set part was to test in develop part and copied the whole thing.
Thanks for the solution!