Condition every second week on wednesdays

Hi! I want to set a condition that fire a reminder every second week on wednedays. I can’t figure out how to do- plaese help.

You can do the Wednesday bit easy enough:

condition:
  condition: time
  weekday:
    - wed

You will probably have to use an input boolean for the ‘every second week’ bit (unless anyone can come up with a smarter way).

Write an automation to toggle this input boolean every week before Wednesday (every Tuesday at noon for example). So it is on for a week, then off for a week, on for a week, etc…

Then you can just add a condition to check it’s state:

condition:
  - condition: time
    weekday:
     - wed
  - condition: state
    entity_id: input_boolean.bi_weekly
    state: 'on'

Use this thread to figure out what week you are in and then either filter for odd or even weeks…

2 Likes

This will give you even weeks, add it to your conditions:

{{(as_timestamp(now())|timestamp_custom ('%U') | int % 2) == 0 }}

change it to ==1 for odd weeks

4 Likes

Nice! So if the condition is true then it’s fire the actions?

You need a trigger. An easy one would be the time you want the reminder to show.
Then the conditions would be the weekday Wednesdays and the odd/even week.
If all of them are true the action will be performed.

True. Will this work?

   alias: Service - notifikation om soptunnan på dagen
    trigger:
      platform: time
      at: '06:00:00'
    condition:
      - condition: time
        weekday:
             - wed
      - condition: template
        value_template: {{(as_timestamp(now())|timestamp_custom ('%U') | int % 2) == 0 }}
    action:
      - service: notify.mypushbullet
        data:
          title: Kom ihåg
          message: Ställ ut soptunnan
          target: email/[email protected]
      - service: notify.mypushbullet
        data:
          title: Kom ihåg
          message: Ställ ut soptunnan
          target: email/[email protected]
      - service: notify.lg_webos_smart_tv
        data:
          message: Ställ ut soptunnan idag

Did this work for you?

I intergrade Google calender instead.

Hi Henrik,

I’m also using this component, but have you managed to do some sort of Automation based og events from your calendar?

Yes!

alias: Service - notifikation om soptunnan på dagen
trigger:
  platform: state
  entity_id: calendar.privat
  to: 'on'
condition:
  condition: template
  value_template: "{{states.calendar.privat.attributes.message == 'Ställ ut soporna' }}"
action:
  - service: notify.mypushbullet
    data:
      title: Kom ihåg
      message: Ställ ut soptunnan
      target: email/[email protected]
  - service: notify.mypushbullet
    data:
      title: Kom ihåg
      message: Ställ ut soptunnan
      target: email/[email protected]
  - service: notify.lg_webos_smart_tv
    data:
      message: Ställ ut soptunnan idag
1 Like

Thanks!
Works perfectly!

Thanks @datamonkey. That worked for me. For future searchers here are 2 automations that fire on alternate weeks using the value_template to identify the week number…

- id: '111' 
  alias: Email Bin Night Blue
  trigger:
    platform: time
    at: "17:00:00"
  condition:
    - condition: time
      weekday:
      - tue
    - condition: template
      value_template: "{{(as_timestamp(now())|timestamp_custom ('%U') | int % 2) == 1 }}"
  action:
  - data:
      message: Take out the bins. Tonight it is Recycling (Blue)
      title: Bin Night! (blue)
    service: notify.gmail

- id: '222' 
  alias: Email Bin Night Red
  trigger:
    platform: time
    at: "17:00:00"
  condition:
    - condition: time
      weekday:
      - tue
    - condition: template
      value_template: "{{(as_timestamp(now())|timestamp_custom ('%U') | int % 2) == 0 }}"
  action:
  - data:
      message: Take out the bins. Tonight it is Green Waste (Red)
      title: Bin Night! (red)
    service: notify.gmail

7 Likes

thank you using your template this works great.
YOU ROCK.

thank you for this template
you rock.

If you’re interested, you can reduce this:

value_template: "{{(as_timestamp(now())|timestamp_custom ('%U') | int % 2) == 1 }}"

to this:

value_template: '{{ now().isocalendar().week is odd }}'

Both templates do the same thing; they determine if the current week number is an odd number.

1 Like

here is mine for reminder to take cans and if both up. plays a video on tv and announcement on google mini.

- id: '1650599030716'
  alias: trash and recycle reminders calendar even days
  description: 'play video on TVS and announcement on google mini''s to take up green
    recycle and black trash can. '
  trigger:
  - platform: time
    at: '18:29:00'
  condition:
  - condition: time
    weekday:
    - wed
    before: 00:00:00
    after: 00:00:00
  - condition: template
    value_template: '{{(as_timestamp(now())|timestamp_custom (''%U'') | int % 2) ==
      0 }}'
  action:
  - service: media_player.play_media
    target:
      entity_id: media_player.nestmini7847
    data:
      media_content_id: media-source://tts/cloud?message=both+cans+need+to+go+up+this+week+see+alert+on+tv&language=en-US&gender=female
      media_content_type: provider
    metadata:
      title: both cans need to go up this week see alert on tv
      thumbnail: https://brands.home-assistant.io/_/cloud/logo.png
      media_class: app
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://tts
      - media_content_type: provider
        media_content_id: media-source://tts/cloud?message=both+cans+need+to+go+up+this+week+see+alert+on+tv&language=en-US&gender=female
  - service: media_player.play_media
    target:
      entity_id: media_player.livingroomtv
    data:
      media_content_id: media-source://media_source/local/bothcans.mov
      media_content_type: video/quicktime
    metadata:
      title: bothcans.mov
      thumbnail:
      media_class: video
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
  - service: media_player.play_media
    target:
      entity_id: media_player.bedroom_tv
    data:
      media_content_id: media-source://media_source/local/bothcans.mov
      media_content_type: video/quicktime
    metadata:
      title: bothcans.mov
      thumbnail:
      media_class: video
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
  mode: single
- id: '1650637963908'
  alias: 'trash  reminders  ODD week '
  description: 'play video on TVS and announcement on google mini''s to take up only
    black trash can. '
  trigger:
  - platform: time
    at: '18:29:00'
  condition:
  - condition: time
    weekday:
    - wed
    before: 00:00:00
    after: 00:00:00
  - condition: template
    value_template: '{{(as_timestamp(now())|timestamp_custom (''%U'') | int % 2) ==
      1 }}'
  action:
  - service: media_player.play_media
    target:
      entity_id: media_player.nestmini7847
    data:
      media_content_id: media-source://tts/cloud?message=Garbage+only++needs+to+go+up+this+week+see+alert+on+tv&language=en-US&gender=female
      media_content_type: provider
    metadata:
      title: Garbage only  needs to go up this week see alert on tv
      thumbnail: https://brands.home-assistant.io/_/cloud/logo.png
      media_class: app
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://tts
      - media_content_type: provider
        media_content_id: media-source://tts/cloud?message=Garbage+only++needs+to+go+up+this+week+see+alert+on+tv&language=en-US&gender=female
  - service: media_player.play_media
    target:
      entity_id: media_player.livingroomtv
    data:
      media_content_id: media-source://media_source/local/garbage.mov
      media_content_type: video/quicktime
    metadata:
      title: garbage.mov
      thumbnail:
      media_class: video
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
  - service: media_player.play_media
    target:
      entity_id: media_player.bedroom_tv
    data:
      media_content_id: media-source://media_source/local/garbage.mov
      media_content_type: video/quicktime
    metadata:
      title: garbage.mov
      thumbnail:
      media_class: video
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
  mode: single

Your first automation is named:

trash and recycle reminders calendar even days

If it’s meant to only run on even days, why is it using the Template Condition for determining odd weeks?

Or is the automation’s name not indicative of what it’s supposed to do?

well it looks like i copied my test YAML and not my working one. and did not change the == 1 to ==0

thanks for the catch

The problem with using week number is that if you have 53 weeks then you will get two odd weeks after each other.

                                                   | Because I'm 1 hours ahead of UTC (I disregard summertime because the int will flatten it out anyways), replace this with your timezone
{{ ((now().timestamp() | int-(86400*5)-(now().hour-1)*3600) / 604800) |int is odd}}
                                ^ because 1970-01-01 was a Thursday 

Calculates the number of weeks from UTC and thus should give you a correct every other week condition.

1 Like