WTH why I can't use full cron time expressions in Time pattern trigger?

I would like to use it for example to switch on my air purifier to check the AQI every 5 minutes and then switch off after 1 min if it’s OK.

I would write */5 * * * * then in the second task 1,6,11,16,21,26,31,36,41,46,51,56 * * * * but I can’t do this now.

/5 is there but that’s all.

Please support full crontab expressions!

Whilst I like the idea of adding cron patterns you would be far better off making this state driven to mimise the number of needless triggers.

Numeric state trigger: AQI > whatever → action: turn the purifier on.

State trigger: fan on for 1 min → action turn the purifier off.

Or better yet, numeric state trigger: AQI < whatever → action turn the purifier off.

Time pattern triggers are rarely the best way to automate.

I tried to do as you told me but wasn’t able. My air purifier tells me the AQI, I can switch it on by time pattern /5, but wasn’t able to switch off when the AQI is <= 1 for one minute. Because Numeric state trigger only fires on change it won’t fire if it stays the same. So if I start with 1 when switching on then won’t switch off.

My attempt was this:

- id: '1664613162841'
  alias: AQI 1 switch off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.zhimi_v7_df85_pm25_density
    for:
      hours: 0
      minutes: 1
      seconds: 0
    attribute: environment.pm2_5_density
    below: 2
  condition: []
  action:
  - type: turn_off
    device_id: 80da6cc95b3d3353ea7058a9465d864b
    entity_id: switch.zhimi_v7_df85_switch_status
    domain: switch
  mode: single

Go to Developer Tools → States and take a screenshot of the attributes column for sensor.zhimi_v7_df85_pm25_density

In Developer Tools → Templates, what does this return:

{{ state_attr('sensor.zhimi_v7_df85_pm25_density', 'environment.pm2_5_density') }}

Did the pm2.5 level ever go above 2?

It has to cross from above 2 to below 2 to trigger.

Sometimes does, then the automation would work, but usually it stays at constant 1. This is why I want to automate it to periodically check and only use the filter/electricity when needed.

At the moment the switch on is /15 and the check if 1 then switch off at /7. But it is ugly. This is why I need the normal cron expression.

No you don’t.

This is your turn off trigger if you want to do it by time:

  trigger:
  - platform: state
    entity_id: switch.zhimi_v7_df85_switch_status
    to: 'on'
    for:
      minutes: 1 # or whatever

Also try quoting the the attribute for this trigger:

  trigger:
  - platform: numeric_state
    entity_id: sensor.zhimi_v7_df85_pm25_density
    for:
      hours: 0
      minutes: 1
      seconds: 0
    attribute: 'environment.pm2_5_density'
    below: 2

I would love having cron as an option. This would be optimal for automations that you want to fire every other Wednesday, the 1st of the month, or the first Thursday. Or maybe you want a script that runs annually or every 4 months.

It could also be a handy condition. Maybe you want a condition that only fires on even days or only works in July.

Templates could be used, but I think there is a strong argument that supporting CRON is worth it since a lot of people are familiar with it.

Tom! You are right with the switching on without cron. But the check and switching off don’t work if I quote the attitude or not. In the documentation it is written clearly that numeric state trigger only works if there is a change, if it stays the same for days it won’t activate.

Not what that trigger is for:

It the purifier switch has been on for a minute, then turn it off. No cron required.

Oooo I got it. I’ll give it a try! Thanks!

It works!!! You are the best! Thanks a lot!

1 Like