Need help with automation not firing

I have a heater in my greenhouse which is connected via a smart plug. I want to turn it on when the outside temperature (which I get from OpenWeatherMap) is below 5° and the temperature in the greenhouse (which I get from a Sonoff sensor) is below 7°.

I’ve created an automation using the GUI, which specifies a trigger for the outside temperature below 5, and a condition that the sensor in the greenhouse is reading below 7.

It’s now 1.2° outside according to OpenWeatherMap, and the greenhouse sensor is showing 5.2°. The automation hasn’t fired.

What have I done wrong?

We can’t help without you showing use your codes. Make sure you format it correctly when pasting.
Select this when pasting your codes.

I’m guessing that when the outside temperature goes below 5 your condition is not yet below 7 so the actions will never run. The only way this would work is if both are true at exactly the same time.

If this is the case then you probably need a template trigger to logically ‘and’ the two conditions (<5 AND <7). If you don’t want to get into templates then the following post expalins another method:

Hope that helps.

I can’t easily show the codes as the automation was created via the GUI. I don’t see a way to display the equivalent YAML.

Thanks, I will investigate templates, but I found the documentation confusing last time I lookee.

No problem, look at the linked article instead … for this you need both items in your trigger and also both in the condition but as an AND.

OK, so my automation has two triggers:
(1) outside temp < 5, and
(2) inside temp < 7

  • these are logically "or"ed, so if either happens, the automation moves on to check the conditions.

The conditions are in effect the same:
(1) outside temp < 5, and
(2) inside temp < 7

  • but here they are "and"ed, so the action will fire if both are true.

Thus it makes no difference which trigger happens first, the automation fires as soon as both are true.

Have I understood this?

If you go to the automation UI editor there should be a way to see the yaml.

open the three-dot menu in the top right and select “edit as yaml”. then copy that code here.

Yes, you have understood this correctly … either will trigger the automation but both have to be true in the conditions for the actions to fire.

1 Like

Ah, right, I see it now. But in any case I have the automation working now. Here’s what I’m using:

alias: Start Greenhouse heating
description: 'Outside temp below 5, if inside temp below 7'
trigger:
  - platform: numeric_state
    entity_id: sensor.openweathermap_temperature
    below: '5'
  - platform: numeric_state
    entity_id: sensor.temperature_4
    below: '7'
condition:
  - condition: numeric_state
    entity_id: sensor.temperature_4
    below: '7'
  - condition: numeric_state
    entity_id: sensor.openweathermap_temperature
    below: '5'
action:
  - service: light.turn_on
    data: {}
    entity_id: light.outdoors
mode: single

This kept the greenhouse temperature steady between 6.5 and 7.5 degrees all night, with the outside temperature going down to just below zero.

Now I just need to make the upper and lower temperature targets variables that I can set through the Lovelace UI.