CalDav Sensor current day event/next day event

Hey everyone! Didn’t find a CalDav component category so because it is supposed to be implemented in my dashboard I’m posting this here :slight_smile:

Does anyone know how I create a sensor that stays on the CalDav Calendar day event even when that event is not happening (even if it’s not a sensor and I have to make a custom widget)?

At the moment the event (in this case my work shift) is only displayed during the shift time so before I go to work and when I come back it says “Off Work”.

Also, is it doable to make another sensor/custom widget to show what the event of tomorrow is?

This is the code I’m using for my “Today shift”:

- platform: template
  sensors:
    next_shift:
      friendly_name: 'Next Shift'
      value_template: >-
        {% if is_state('calendar.work','on') %}
            {{ states.calendar.work.attributes.message }}
        {% else %}
            Off Work
        {% endif %}
    next_shift_time:
      friendly_name: 'Next Shift Time'
      value_template: >-
        {% if is_state('calendar.work','on') %}
            {{ strptime(states.calendar.work.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%H:%M") }} - {{ strptime(states.calendar.work.attributes.end_time, "%Y-%m-%d %H:%M:%S").strftime("%H:%M") }}
        {% else %}
            
        {% endif %}

Looking forward to your answers! Have a great day/evening/night wherever you are! :slight_smile:

the basics to work with is:
A dashboard is there to visualise what is already in HA.
so if you have a working sensor in HA, you can display it on the dashboard.

you seem to have 2 template sensors, so you can use those as a sensor widget.

Hey! Thanks for the reply. The problem is that the sensor is only working during the shift time so from Event Start time to Event End time. I want it to be displayed the whole day and on top of that create another one to show the event of the next day. Is this possible, even if it’s done with a custom widget or different template?

That’s the same problem I have as well.
Is there a way to display the start time of the next/upcoming event, even if it is several days in he future?
I wanted to implement a garbage reminder - but it has to remind me the evening before, while going to bed, not at the day of collection…

Thank you for your thoughts!

the start time from the next upcoming event can be retrieved with a get state
i use it like this:

   self._entity = "calendar.any_name"
    start_time1 = self.get_state(self._entity,attribute = "start_time")
    if start_time1 == None:
      return
    actual_time = datetime.datetime.now()
    in_5_seconds = datetime.datetime.now() + datetime.timedelta(seconds=5)
    self.start_time = datetime.datetime.strptime(start_time1,"%Y-%m-%d %H:%M:%S")
    hour_before_start_time = self.start_time - datetime.timedelta(minutes=60)
    half_hour_before_start_time = self.start_time - datetime.timedelta(minutes=30)
    half_time = self.start_time + datetime.timedelta(minutes=50)
    game_ended = self.start_time + datetime.timedelta(minutes=130)

    if hour_before_start_time > actual_time:
      self.run_at(self.game_in_a_hour,hour_before_start_time)
    if half_hour_before_start_time > actual_time:
      self.run_at(self.game_in_a_half_hour,half_hour_before_start_time)
    if self.start_time > actual_time:
      self.run_at(self.game_now,self.start_time)
    if self.start_time < actual_time and actual_time<game_ended:
      self.run_at(self.run_liveverslag,in_5_seconds)
1 Like

Thanks again for the help Rene! Coming from coding with other languages I understand the code, but I’m not sure where the put it? In the template I made? In a custom widget? Somewhere else? Sorry I’m still a noob at HA and it’s coding! :slight_smile:

the code i gave is a part from an app.

you have appdaemon with HAdashboard installed, so you can use apps.
i think for someone with a programming background thats the best place to create automations.

to understand more about it, you can read all about it here:
http://appdaemon.readthedocs.io/en/latest/TUTORIAL.html
also the parts “writing appdaemon apps” and “appdaemon API reference” are then word reading.

i know its a lot to read, but if you are a programmer, then you love the options that you have afterwards.

the link i gave is for the latets version from appdaemon/hadashboard

Thank you for your help.
I read about that in another topic, but was still hoping theres a way inside hass to get the same result.

I am about to get warm with appdaemon, as I am still struggling with the new version and occusim, which is not working.
When its done I will come back to this.
Thanks again!

It looks like this is what you have now if I’m understanding correctly.

{% if is_state('calendar.work','on') %}
    {{ states.calendar.work.attributes.message }}
{% else %}
    Off Work
{% endif %}

Since it’s only to set to show information when the calendar is set to on which would occur when the event is occuring. If it is set to show info if the calendar has a start_time available then it will show before, during, and for a brief few seconds after the event is done.

{% if states.calendar.work.attributes.start_time %}
  {{ (as_timestamp(states.calendar.work.attributes.start_time) | timestamp_custom('%A at %I:%M %p')).replace(' 0',' ') }}
{% else %}
  Shift unavailable
{% endif %}

I may be way off but at least it’s still kind of a relevant response.