WTH don't we have a cron time trigger

This been mentioned before (see bottom) but the timer trigger is limited, and a cron timer would give us so much more flexibility.

I would like to setup an automation that fires:
At 16:00 monday, thuesday, wednesday
At 18:30 on thuesdays
At 15:30 on friday
During winter time.

So for first example i would use this trigger 00 16 1 JAN,FEB,MAR,SEP,OCT,NOV,DEC MON-WED
Since 00 16 1 SEP-MAR MON-WED does not really seems to be supported?

I don’t see how i would be able to set up that as one automation with current features, but it would be really easy with cron support. Then i would just define 3 triggers for the same automation

Condition: day [was “Schedule” Trigger type]

Cron / Periodic

Time_pattern more like crontab

This was one of the reasons I moved my automations to Node-Red. There is a “true” cron feature: https://discourse.nodered.org/t/update-v1-2-1-node-red-contrib-cron-plus-scheduler-incl-solar-events-and-timezone-support/13686/270

Simple and while a lot more verbose, it is a lot easier to read than the cron syntax:

trigger:
 platform: time
 at: 
  - "16:00"
  - "18:30"
  - "15:30"
condition:
- condition: state
  entity_id: sensor.season
  state: "winter"
- condition: or
  conditions:
  - condition: time
    after: "15:59"
    before: "16:01"
    weekday:
    - mon
    - tue
    - wed
  - condition: time
    after: "18:29"
    before: "18:31"
    weekday:
    - tue
  - condition: time
    after: "15:29"
    before: "15:31"
    weekday:
    - fri
action:
- etc...
2 Likes

I think the real reason that we don’t have full cron support is that it is complex and error-prone.

The frequently used parts are already possible with a combination of triggers and conditions. For your example where you want three of them, I would move the action to a script and make three different automations.

I guess you mean 00 16 * JAN,FEB,MAR,SEP,OCT,NOV,DEC MON-WED but I had to look up the syntax to be sure.

If you can read and write yaml, I tend to disagree… Especially, if you go to eg. https://crontab.guru/

Well then we’ll just have to agree to disagree. In favour of my side is your mistake in this:

00 16 1 JAN,FEB,MAR,SEP,OCT,NOV,DEC MON-WED

(only on the first day of the month).

Where as it is quite clear in my conditions above.

I have Node-Red setup so might consider moving this part to Node-Red.

@ tom_l i am not a fan of separating the trigger and the condition, sure it works. But it makes it harder to read and understand.

And there is really good tools to help build good cron expressions, for example https://crontab.guru/ were mentioned before.

Thanks for the Node-RED tips. Got this setup really fast.

Now i am ready for the winter and i don’t need to manually enable the car heater thru the Volvo on Call app. Now my smart home will know the car is at work and then its time to heat up :slight_smile:

With CRON trigger, this flow is really clean.

1 Like

Glad I could help!!
In addition, I guess you saw than you can use msg input to create/update/delete entries in the cron node. So, you can, eg. enable cron if the temperature below is less than X°C independently of whether it is officially “winter”.

No one ever took a chance to implement crontab-like trigger, for example using ApScheduler lib (https://apscheduler.readthedocs.io/en/stable/) :confused:
The person who do this will be our hero :stuck_out_tongue:

cron.guru and Node Red cron will “translate” the syntax in plain English.
With yaml (at least for me), it is quite difficult to test without multiple trial/error.
But, I agree, and said it many times already, the very good thing with HA is that you can do your “stuff” in yaml, nodered or python depending on your appetite. So, everyone’s happy :slight_smile:

Been thinking about adding condition for the weather later on. For now Volvo on Call will not start the heater if the temperature is above 15 degrees Celsius.

I still don’t see any decent Cron type options. This is a big hold up for trying to migrate from OpenHAB. A lot of my rules are seasonal and explicitly run on certain days or times.

Maybe use this:

There’s nothing you can do in cron syntax that can’t be done in a template. Case in point, here’s the example at the top in one template trigger:

trigger:
  platform: template
  value_template: >-
    {{ (now().hour == 16 and now().minute == 0 and now().weekday() < 3
      or now().hour == 18 and now().minute == 30 and now().weekday() == 3
      or now().hour == 15 and now().minute == 30 and now().weekday() == 4)
      and (now().month < 4 or now().month > 8) }}

I’m all a fan of making this easier with a UI scheduler. Either bringing something like Edwin is showing to core or a local calendar option so we can build schedules in HA to use with the new calendar trigger.

But bringing cron syntax to HA? Why? HA already has one extremely technical syntax that can do everything cron can do and more and people already struggle to learn that. HA doesn’t need another language for people to learn.

1 Like

I found SimpleScheduler but it seems the sort of thing that would be smart to bake into the core. Not everyone is good with YAML. One of the things I love about OpenHAB is I can be very sloppy as long as the right syntax is there. Spacing doesn’t make a lick of difference. I have some rules set to run 7 days a week and others on weekdays. Some are all year, some are specific months.