How to automation can set the state of workday

Hi,

I’m using a Google calendar to getting public holidays. So I want to change the workday state from a automation. I have a template gives me ‘workday’, ‘weekend’ or the name of the public holiday.

Now I try to update the binary sensor workday to off if the state of this template is not ‘workday’. Any idea how to make this?

Regards, Steffen

Maybe it could be done in Jinja then I do not need a automation? Here is my template:

platform: template
sensors:
  tmp_arbeitstag:
    friendly_name_template: Tagestyp
    entity_id:
      - sensor.date
      - binary_sensor.arbeitstag
    value_template: >-
      {% set today = as_timestamp(now()) %}
      {% set next = as_timestamp(state_attr('calendar.feiertage_hessen','start_time')) %}
      {% set offset = ((next-today)/86400) %}
      {% if (offset) <= 0 %}
        {{ 'Feiertag: ' ~ (states.calendar.feiertage_hessen.attributes.message) }}
      {% else %}
        {% if is_state('binary_sensor.arbeitstag', 'off') %}
          Wochenende
        {% else %}
          Werktag
        {% endif %}
      {% endif %}

Something like ‘set_state(‘binary_sensor.arbeitstag’,‘off’)’ at the first if?

Steffen

Hi Steffen,

if you are just interested in a binary sensor for workday, you can use the builtin platform workday. See https://www.home-assistant.io/integrations/workday/
The first part of the code snippet below enables this sensor for Niedersachsen. You have to set ‘HE’ for Hessen.

For my use case I extended this by adding a Google calendar for my vacations. Each vacation day gets a full-day appointment. The second snippet aggregates these two values into a binary sensor called template_workday.

Hope this helps,

Lutz

# Germany/Niedersachsen
- platform: workday
  country: DE
  province: NI


# this template sensor combines workday-sensor above and the holiday-calendar
- platform: template
  sensors:
    template_workday:
      friendly_name: "Arbeitstag"
      value_template: >-
        {{ (states.binary_sensor.workday_sensor.state == 'on') and (states.calendar.vacation.state == 'off') }}
2 Likes

If the Workday Binary Sensor does not have all the holidays you need (for your country), you can add holidays.

add_holidays
(list)(Optional)

Add custom holidays (such as company, personal holidays or vacations). Needs to formatted as YYYY-MM-DD.

Thanks, manually adding the holidays to the yaml is not the way i want to go.

1 Like

Thanks, I’m using the workday platform but I do not know the province option.

Till now the workday platform only are on weekends off and not at the public holidays.

So with the option the workday platform change the state to ‘off’ on the official public holidays at the province?

Regards, Steffen

Yes, it does.
As I wrote above you can add your personal vacations to a Google calendar and create a custom workday sensor.

1 Like