Newbie Templating Question

Hello,

I’ve been on HA almost a month and I know enough to be dangerous. With that said, I have two very simple templating questions.

I’ve gotten far enough to figure out how to average the temperature of two sensors per the instructions on the templating docs page:

template:
  - sensor:
      - name: "Average Outdoor Temperature"
        unit_of_measurement: "°F"
        state: >
          {% set front_door_trisensor = states('sensor.front_door_trisensor_air_temperature') | float %}
          {% set garage_door_trisensor = states('sensor.garage_door_trisensor_air_temperature') | float %}

          {{ ((front_door_trisensor + garage_door_trisensor) / 2) | round(1, default=0) }}

I plugged it into dev tools and it gives me the answer I expect:
2022-01-24 21_37_19-Greenshot

It’s at this point, I get a little lost in the weeds and I don’t know which action is appropriate.

I ultimately want to make an automation trigger when the average of these two temperature sensors drops below 40F
Now that I have a sensor built that averages the two temperature sensors, when I try to build the automation, it’s not really setup in a way like “drops below”


This doesn’t seem right and I think I’m lost/this won’t work.

Should I be triggering the automation off of a value template that already has the average temp of these two sensors with the offset for 40 degrees?

I need an automation that will trigger when the average temp of these two sensors drops below 40 sensor.front_door_trisensor_air_temperature and sensor.garage_door_trisensor_air_temperature

I need another automation that will trigger when the average illuminance of these two sensors drops below 150 sensor.garage_door_trisensor_illuminance and sensor.front_door_trisensor_illuminance. With help on the temperature, I can probably meander my way through the illuminance.

I know I’m missing a step and I think it’s because I’m confusing two different ways of implementing this trigger.

You can use a template that says “((sensor_1 + sensor_2) / 2) < 40” to trigger the automation and skip creating another sensor just for that one purpose.

but since you already have the sensor you could also use the ‘numeric-state’ trigger and set tht so the average sensor below 40 to do the trigger.

That was so incredibly obvious and makes perfect sense lol. I already plugged it in and now I can see how to do the same thing with illuminance. ((sensor.front_door_trisensor_air_temperature + sensor.garage_door_trisensor_air_temperature) / 2) < 40

Thank you

1 Like

Hello,

I know you randomly popped in and provided me with what I thought was the solution. I’ve since discovered it’s not working and I was wondering if you could once again offer some advice.

Any time I use this template for the illuminance, it’s not working. I’ve definitely narrowed it down to this part of the automation.

condition: template
value_template: >-
  ((sensor.front_door_trisensor_illuminance +
  sensor.garage_door_trisensor_illuminance) / 2) < 150

This all seems like it should work but everywhere I used it, it failed. I also tried using “<150 lux” and I got the same non-results.

Do you know what I might be doing wrong or where I can look to investigate?

Here’s a picture to confirm the illuminance data: 2022-01-27 20_33_31-Greenshot

Here it is if I’m just trying to do with straight with 1 sensor:

type: is_illuminance
condition: device
device_id: 2149ea6050af0e14cbc6b68ff1a51ab5
entity_id: sensor.front_door_trisensor_illuminance
domain: sensor
below: 150

Your template is missing a few important parts…

condition: template
value_template: >-
  {{ ((states('sensor.front_door_trisensor_illuminance')|int +
  states('sensor.garage_door_trisensor_illuminance')|int) / 2) < 150 }}
1 Like

thank you, that worked perfectly and I understand why now.

I guess I needed to be more specific on what I wrote.

I was just giving a generic description of what could be done and didn’t mean that you could directly copy it without the correct jinja template syntax surrounding it.

sorry about that.

No worries, I’m learning and I’ve only got 5 templates I need to worry about!