Check if automation is run on the hour (minutes multiple of 0?)

I want to be able to run an automation to request data from a TRV with different frequencies.

  • if the TRV is on a heating cycle request data every 20 mins
  • if the TRV is NOT on a heating cycle request data every hour

The way I would do that into a script would be to run it every 20 mins and then check if the TRV is on a heating cycle; if yes, then continue, otherwise check if we’re running exactly at 00 minutes (so, on the hour) to continue and update the data, otherwise exit.

Unfortunately I cannot see a way to have a condition to check a time besides checking if it is between two values. Isn’t there any way to check attributes of the time?

For now I came up with the following automation

alias: Request data from TRV
trigger:
  - platform: time_pattern
    minutes: /20
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: climate.thermostat_living_room
        attribute: temperature
        above: 12 # we're on a heating cycle
      - condition: # here I need the condition
                        # to check if we're on the hour
                        # so something like minutes // 0
action:
# workaround to update the data on the thermostat,
# manually change the offset
  - device_id: .....
    domain: number
    entity_id: number.thermostat_temperature_offset
    type: set_value
    value: 0
mode: single

You can use a template condition:

  - condition: template
    value_template: "{{ now().minute == 0 }}"

Another option is to alter your trigger and use a trigger condition…

trigger:
  - platform: time_pattern
    minutes: 20
  - platform: time_pattern
    minutes: 40
  - platform: time_pattern
    minutes: 0
    id: hour
condition:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: climate.thermostat_living_room
        attribute: temperature
        above: 12 
      - condition: trigger
        id: hour

Domain number??
What is that?
Why would the TRV not update? What is updating the TRV that Home Assistant is updated on?
What integration is used for this TRV?

Device actions are very verbose… Number entities are essentially the same as Input number entities. They are just created by integrations instead of the user… with the exception of Template numbers which are in the number domain and created by the user.

1 Like

Some of the Zigbee trv that I use have a ‘low energy’ mode where the current temperature reading is never updated unless some specific actions are performed.
I use ZHA, I think there’s no problem with Z2M but I’m not sure as I don’t use it

Thanks, both valid solutions but I was really looking for the first one, I just didn’t know how to use the template condition

Ok… Didn’t know either of this.

So if you don’t force the TRV to update then it won’t shut off.
Seems like a bad design of the TRV from the start. Can’t you use an external temperature sensor?

It’s more complicated than that.

The TRV most likely knows its measured temperature, it just won’t comunicate that over the network to save battery.

In theory there is a switch exposed in HA that you can turn on to temporarily disable this mode and send data to HA but that doesn’t work anymore and for some other TRVs is not needed. As a workaround I just manually set the offset every time to force the trv to communicate the temperature to HA.

This is really not a problem if you set a target temperature for the trv and forget about it as it will locally adjust the heat, but I want to control with an external temperature sensor, as you mention, so is it important to get the most updated temperature

If you have an external temperature sensor then create a generic thermostat and have this control the TRV.
That means all the processing is done on the HA server with just the temperature sensor as input.
When the temperature sensor is “hot” enough then HA can send a command to the TRV to switch off or lower the temperature whichever you want.

I use better thermostat and for the calibration it requires to have a local temperature

Really? Why?
I just use the normal generic thermostat and it works perfectly fine without the local temperature.
(If you mean local as in the TRVs temperature sensor).

yeah, better thermostat also does something more and to do that it needs to know the local temperature measured by the trv to adjust the target one.
If you don’t need something complicated generic thermostat will work as well :slightly_smiling_face: