Monthly automation

Is there any way to run an automation once per month? Looking through the time conditions, there seems to be built-in ways to easily automate weekly. I couldn’t find any way to do the same on a monthly-basis (e.g. on the 1st or 15th).

1 Like

You can trigger your automation daily and add a condition that checks the day of the month.

condition:
  condition: template
  value_template: '{{ (now().strftime("%d") | int) == 1 }}'
3 Likes

This is what I use for the 1st of the month:

- alias: Heartworm and Flee Medication.
  trigger:
    - platform: time
      at: '10:00:00'
    - platform: time
      at: '19:00:00'
  condition:
    - condition: template
      # Change the number here to get whatever day of the month you want.
      value_template: "{{ now().day == 1 }}"
  action:
    - service: notify.ios_petro
      data:
        message: "Give heartworm and flee medication."
        data:
          push:
            badge: 5
    - service: notify.ios_wife
      data:
        message: "<Wifes> turn to give mosby heartworm and flee medication."
        data:
          push:
            badge: 5

I screw with my wife and let her know it’s always her turn, but other than that, this is the automation I use.

9 Likes

Thank you both!

Do someone have also an idea for a trigger per year?
In addtion thank you @petro for the month trigger, well done. :slight_smile:

If I pulled a stunt like this my rpi would find itself in the toilet bowl in an awful hurry. Your wife has a better sense of humour than mine! Which gives me an idea, when I upgrade to a NUC I’m going to leave the rpi plugged in as a decoy! :smile:

2 Likes

I’m late in replying but I didn’t have an answer in February! :slight_smile:

Paste this in the Template Editor and it will report the current ‘year day’ (the day of the year).

{{now().timetuple().tm_yday}}

For example, today is April 15 2019 and the template will report 105.

So to ensure the automation runs only on the first day of any year, do this:

  condition:
    - condition: template
      # Change the number here to get whatever day of the year you want.
      value_template: "{{ now().timetuple().tm_yday == 1 }}"
2 Likes

Have tried to copy your knowledge in automation but gets error “Error loading /config/configuration.yaml: mapping values are not allowed here”

Someone who can help?

  ##

  - alias: Automower maintenance charge on
    trigger:
      - platform: time
        at: '20:00:00'
    condition:
      - condition: template
        value_template: '{{ (now().strftime("%d") | int) == 24 }}'
    action:
      - service.switch.turn_on
        entity_id:
          - switch.001103ab_switch

  ##

  - alias: Automower maintenance charge off
    trigger:
      - platform: time
        at: '22:30:00'
    condition:
      - condition: template
        value_template: '{{ (now().strftime("%d") | int) == 24 }}'
    action:
      - service.switch.turn_off
        entity_id:
          - switch.001103ab_switch

that means you have an incorrect field.

In your case, all your services are wrong. You have:

    action:
      - service.switch.turn_on
        entity_id:
          - switch.001103ab_switch

they should be

    action:
      - service: switch.turn_on
        entity_id:
          - switch.001103ab_switch

Tx, to tired, sometimes you get blind :sunglasses:

1 Like

Hi all,

don’t now if It is necroposting.

But I need to have a time condition in a month range (may to septeber to manage my heating system).

How can I adapt this?

I’m really enjoying this misspelling. I’m imagining you (or your wife, or maybe actually you after she figures out it’s actually your turn) running away after giving the first med…

{{ now().month > 4 and now().month < 10 }}
2 Likes

Hi,
This is my auto restart yaml code that runs at 7:45 on the 15th of every month.

alias: Home Assistant - Auto Restart
description: ''
trigger:
  - platform: time_pattern
    minutes: /15
condition:
  - condition: template
    value_template: >-
      {{  now().strftime('%M')|int == 45 and now().strftime('%H')|int == 7 and now().strftime('%d')|int == 15 }}
action:
  - service: hassio.host_reboot
    data: {}
mode: single
1 Like

Given that you know the exact time when it should trigger, use a Time Trigger.

alias: Home Assistant - Auto Restart
description: ''
trigger:
  - platform: time
    at: '07:45:00'
condition:
  - condition: template
    value_template: "{{ now().day == 15 }}"
action:
  - service: hassio.host_reboot
    data: {}
mode: single
2 Likes

You can also create a local calendar with a reoccurring event. After this you can create an automation to trigger on these events to take the desired actions.

Thanks for all the above!

I do some calculations on my monthly power draw and would like to trigger an automation on the “last” day of each month.

I could envision 12 separate schedule helpers but was hoping for a cleaner solution. Even with 12 schedules I couldn’t handle leap years properly (and while I could live with this - it would always bother me that it wasn’t quite right :slight_smile:

I need to run this at 23:59 on the last day of the month, because I am using a utility helper with monthly reset in my calculation that will reset itself to zero at midnight. (Otherwise I’d run it at 00:01 on the first day of the month and use a solution such as those posted above)

Any thoughts?

you should try it like this:

(Trigger for the last day of the month - #30 by Troon)

1 Like

Thanks!! Nice and clean!

The “best” way to do that would be a time trigger and a template condition, thus:

trigger:
  - platform: time
    at: "23:59:00"
condition:
  - "{{ (now() + timedelta(days=1)).day == 1 }}"
action:
# etc

That triggers once per day, only running the action on the last day of the month.

If you were to use the longer template in a template trigger, that would be evaluated every minute, 1440 times more “wastefully” than the alternative above.

Agreed, that’s actually how I did set it up - and for that reason. Thanks for the confirmation!

1 Like