Automation: switch off when power between quarter past and half is less than

Hello all,

after many years of friendship with Openhab, I came across HA 2 weeks ago and was hooked from the first moment. I immediately bought a thin client PC and am now in the process of implementing my smart solutions.

Last year I bought a bar fridge which is located in the garage. It can be switched via a Shelly Plug S. A measurement showed that it consumes about 2kWh per day, which in today’s times can quickly become an ‘expensive’ pleasure.

By clever (smart) switching I was able to reduce the consumption to 0.5kWh without cooling losses.

The whole thing I controlled via rules that look at the power of the socket.

At every full hour (between 09:00 and 22:00) the refrigerator is switched on.
The compressor runs and needs about 175W. At some point the compressor shuts off because the temperature is reached. Then only one fan is running which needs 30W.

Now a rule says: if power between quarter past and half past is less than 25W switch off the socket.

At the full hour it starts from the beginning.

In Openhab I could realize this via a cron condition

when
    Time cron "0 15-30 21-10 ? * MON,TUE,WED,THU,SUN *"
then

Don’t get confused - I have several rules that also consider Fri and Sat.
How can I realize such an automation in HA?
Is it possible to work with cron triggers here too?

https://www.home-assistant.io/docs/automation/trigger/#time-pattern-trigger

https://www.home-assistant.io/docs/scripts/conditions/#time-condition

alias: Switch fridge on
trigger:
  - platform: time_pattern
    minutes: "0"  # matches every hour
condition:
  - condition: time # only between 9am and 10pm
    after: '08:59:59'
    before: '22:00:01'
    weekday: # on these weekdays
      - mon
      - tue
      - wed
      - thu
      - sun
action:
  - service: switch.turn_on
    target:
      entity_id: switch.fridge
alias: Switch fridge off
trigger:
  - platform: numeric_state # when fridge power is <25W
    entity_id: sensor.fridge_power
    below: 25
condition:
   condition: template # and it is quarter past to half past the hour
   value_template: "{{ 14 < now().minute < 31 }}" 
action:
  - service: switch.turn_off
    target:
      entity_id: switch.fridge

great, thanks a lot. That’s what i’m looking for:)

1 Like