An alarm clock adjusting to Magister iCAL calendar

Is it also possible to get only the time ,so without the date and the +01:00

Hi Frank, Iā€™m assuming you are asking this because you want to show something pretty on your dashboard. My take on this:

image

For the ā€œMorgen 06:50ā€ string, I use this template sensor called sensor.moment_nextup_lesson_magister (to add to your dashboard):

template:
  - trigger:
      - platform: state
        entity_id: sensor.date
      - platform: state
        entity_id: sensor.nextup_lesson_magister
      - platform: state
        entity_id: input_number.magister_offset
    sensor:
    - name: Moment nextup lesson Magister
      unique_id: moment_nextup_lesson_magister
      state: >-
        {% set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
        {% set event = states('sensor.nextup_lesson_magister') | as_timestamp(default=0) %}
        {% set delta = ((event - midnight) / 86400) | int %}
        {% if is_state('sensor.nextup_lesson_magister','') %} Onbekend
        {% elif delta < 0 %} Onbekend
        {% elif delta == 0 %} Vandaag {{ (states('sensor.nextup_lesson_magister')|as_timestamp(default=0) - (states('input_number.magister_offset')|int(default=90) * 60)) |timestamp_custom('%H:%M', true)}}
        {% elif delta == 1 %} Morgen {{ (states('sensor.nextup_lesson_magister')|as_timestamp(default=0) -(states('input_number.magister_offset')|int(default=90) * 60)) |timestamp_custom('%H:%M', true)}}
        {% else %} Over {{ delta }} dagen {{ (states('sensor.nextup_lesson_magister')|as_timestamp(default=0) - (states('input_number.magister_offset')|int(default=90) * 60)) |timestamp_custom('%H:%M', true)}}
        {% endif %}

For your specific question, the template is shown in the last line, check the timestamp_custom.

ok thanks
even in het nederlands maar klopt het als ik dit allemaal opnieuw in mijn template.yaml zet dat ik dan ook even moet wachten voordat ik ook werkelijk de tijden zie? natuurlijk heb ik wel mijn yaml geherladen

If you copy exactly my yaml, you can trigger an update by changing the offset.

ok thanks
i have now seen what was going wrong , the ical intergration name the sensors ical_ical_magister, so i have change that and now its is working
thanks

I have clicked on each and every link within the Magister web app, but I canā€™t find any iCal link. I guess that means calendar sharing is disabled by the school?

Hoi Bart ,
Bij je onder je eigen naam ingelogd of 1 van je kinderen want je moet bij het account kijken van wie magister is anders zie je het kopje agenda delen niet

Aha, ik was als mezelf ingelogdā€¦

I love this with two kids who can never get out of bed :slight_smile:
Iā€™m stuck at triggering the alarm. The automations runs on the right time but never gets past the second condition.
What am i doing wrong?

Hello @efraim, there seems to be nothing wrong with the template. I think you should check out the different elements of the template in Developer Tools > Templates. Copy and paste this and check if it produces expected values:

{{ states('sensor.nextup_lesson_magister_pien') }}
{{ states('input_number.magister_offset_pien') }}
{{ states('sensor.date') }}

One thing that comes to mind: do you have the Time & Date integration configured?

@Emphyrio Thanks, iā€™m not sure how to do this. if i parse this i get an error?:
image

If i look at the values of the sensors all seems ok? (and date/time integration configured)
image

@Emphyrio First of all, thank you for your efforts in this project. Most steps are fullfilled in my setup after following your instuctions, although I donā€™t fully comprehend everything I did. All prerequisites are filled; and sensors for 50 ical_magister_events are visible in Dev. tools states. However, not all seems to work as it should.
I need some help with your step ā€œCreate a template sensor that contains the date and time for the next ā€˜first lesson of the dayā€™.ā€ In this sensor I assume you can determine the actual first lesson the next school day. But how do you create/edit this template sensor? What I did was create a new template sensor helper for it but where do I put the first line of the code? Or should I manually put this code in configuration.yaml? Thanks in advance
I got it working, after creating a templates.yaml with your code and including it in config. Works great, thanks a lot!
One remark to the second step in your instructions:

Install the iCal Sensor add-on through HACS. Follow the instructions to add it to your integrations. Configure it to look a maximum of 14 days into the future and for 50 events (=50 sensors). Name it ā€˜ical_magisterā€™ to make it work with the following templates.

I recommend to name the calendar just ā€˜magisterā€™ (rather than ā€˜ical_magisterā€™ in your instructions) or the sensors will be named ā€˜sensor.ical_ical_magister_event_xā€™

@ChielB Thanks for sharing. I changed the starting post with your suggestion, ā€˜magisterā€™ instead of ā€˜ical_magisterā€™.

My Home Assistant configuration is indeed old school, everything is in YAML. This alarm clock should probably be a blueprint now. Perhaps if I find some spare time I could check that out.

1 Like

I made a mistake with the template formatting in my previous post, my apologies. Fixed it in the post. But I donā€™t see anything wrong with the pieces of info you posted. Perhaps check out your log?

Also you can fake trigger the alarm for testing purposes. In Developer Tools > States > find sensor.ical_magister_pien_event_0 > click on it > at the top of the screen change the attribute ā€˜startā€™.

@Emphyrio When / how often does the ā€œsensor.description_of_next_up_lessonā€ update? My kidā€™s first lesson was dropped today in Magister but obviously the alarm was still running at the original scheduled time. Is there a way to update this manually or maybe even make an automation for this sensor (and thus the alarm) to update? In case there is a temporary change in the schedule the alarm automation adapts accordingly? Furthermore, this works like a charm. Thanks!

Hi @ChielB, the sensors should update with any change in the state of the ā€˜ical_magisterā€™ sensors. So the alarm should have adjusted when the lesson was dropped. Perhaps the lesson was dropped from Magister after the alarm time? Also, there is a sync delay so it takes a little time for Home Assistant to pick up the change after the ā€œroster makerā€ (is that a word?) drops the lesson from Magister.

(The alarm actually triggers on sensor.nextup_lesson_magister, not on sensor.description_of_nextup_lesson. But the same update mechanism applies to both sensors).

Thanks for the prompt reply @Emphyrio. The dropped first lesson was visible in Magister prior to the alarm time - I manually disabled the alarm to minimise the expected teenager morning mood :sweat_smile:
I wonder what the normal sync delay is then, is there anything to say about that?
What I did was manually reload some YAML configuration in Developer Tools, like ā€œinput date timesā€ and ā€œtemplate entitiesā€ and after that the amended alarm showed. Not sure what activated that, but I figured I might automate that refresh prior to the set alarm?
Letā€™s make roster-maker an official term here! :joy:

I found the iCal integration syncs every 2 minutes. Should be fairly quick. I donā€™t know why you needed to reload stuff.

1 Like