Automation to trigger on temperature and control a switch

Hi,

I would like to have a automation that triggers on above/below temperatures and then switch on/off a switch.

For some reason I am not able to get it working

- id: 'Turn_on_fridge'
  alias: Turn on fridge
  description: Turn on fridge
  trigger:
  - entity_id: sensor.mobile_temp_sensor_11_0
    platform: numeric_state
    above: 7
  condition: []
  action:
  - entity_id: switch.fibaro_plug_1_4
    domain: switch
    type: turn_on
  mode: single

- id: 'Turn_off_fridge'
  alias: Turn off fridge
  description: Turn off fridge
  trigger:
  - entity_id: sensor.mobile_temp_sensor_11_0
    platform: numeric_state
    below: 4
  condition: []
  action:
  - entity_id: switch.fibaro_plug_1_4
    domain: switch
    type: turn_off
  mode: single
  

Any ideas?

When you determine that it doesn’t work, does the sensor do this (from the docs)?

Fires when the numeric value of an entity’s state (or attribute’s value if using the attribute property, or the calculated value if using the value_template property) crosses (and only when crossing) a given threshold.

You can test by manually changing the sensor state in DevTools->States

Otherwise, it would be helpful for you to describe your test where it isn’t working.

1 Like

The yaml looks fine.

1 Like

After som sleep I realized that this yaml file wasn’t loaded :face_with_symbols_over_mouth:
Now it works as expected :smiley:

Thanks @rccoleman and @Joe3 for your support

It looks like you created a manual version of a generic thermostat.
Keep in mind this automation will fail if the temperature crosses 7 (or 4) during a restart.

Generic Thermostat - Home Assistant (home-assistant.io)

Setting it up as a ac_mode: true should give you what you want.

climate:
  - platform: generic_thermostat
    name: fridge
    heater: switch.fibaro_plug_1_4
    target_sensor: sensor.mobile_temp_sensor_11_0
    min_temp: 0
    max_temp: 10
    ac_mode: true
    target_temp: 5
    cold_tolerance: 0.5
    hot_tolerance: 0.5
    precision: 0.1
1 Like

Thanks @Hellis81

Yes, I noted that during my testing.
However, I bought a old/used fridge due to my sons exam party tomorrow and the thermostat didn’t work. Either full or nothing (more or less).
So I set it full/max, and then have a Z-wave switch and a MySensor so on/off power to keep it into the span. So it is good enough for now.

However, if I am going to keep the fridge after the party I should do a more fail-safe solution and your input is very valuable, thanks