Wildcard/Omit Portion/Parse phrase with in attribute value of sensor/calendar

So our school district has finally made a shared calendar for all the school holidays. Previously I had put in the no school day manually, but just labeled them “No School” so it was easy to parse for templates/automations. The shared calendar states the holiday and then follows it with “Schools Closed”. If I can use just the shared calendar I can clean up the family calendar just a little bit.

I currently use this as my School/No School sensor where “No School” is an all day event created manually.

          {% if is_state('sensor.date_dayoftheweek', 'Sunday') %}
            No School
          {% elif is_state('sensor.date_dayoftheweek', 'Saturday') %}
            No School
          {% elif is_state_attr('calendar.camp','message', 'No School')%}
            No School
          {% else %}
            School
          {% endif %}

I would like to use the shared calendar, but do not know how to omit some text/parse out just the phrase. The shard calendar looks something like this, the “Schools Closed” is always at the end of the holiday name though.

calendar.park_ave_pta

message: Labor Day - Schools Closed

Anybody have an idea?

Thank you!!

- platform: template
  sensors:
     school_status_new:
       friendly_name: "School Status New"
       value_template: >-          
          {% if is_state('sensor.date_dayoftheweek', 'Sunday') %}
            No School
          {% elif is_state('sensor.date_dayoftheweek', 'Saturday') %}
            No School
          {% elif state_attr('calendar.park_ave_special_day','message') | regex_findall("Schools Closed",ignorecase=True) | join(' '), 'Schools Closed'%}
            No School
          {% else %}
            School
          {% endif %}   

This appears to be working so far in case anyone else comes across this. Thanks!

1 Like

small update for what is working for me:

          {% if is_state('sensor.date_dayoftheweek', 'Sunday') %}
            No School
          {% elif is_state('sensor.date_dayoftheweek', 'Saturday') %}
            No School
          {% elif state_attr('calendar.park_ave_special_day','message')| regex_findall('Schools Closed',ignorecase=True) | join(' ')%}
            No School
          {% else %}
            School
          {% endif %}