I need help with a little project

Hi all

I need a help with a little project, I scrape some events from the web and store them in sensors “sensor.match_time_one” which is the time of the event.

I need to create another sensor showing “Next event”

This doe not work, just to demonstrate the idea
can someone please show me the correct approach to do this

binary_sensor:
  - platform: tod
    name: Event 1
    time: “sensor.match_time_one”
    before_offset: 15 minutes
    after_offset: 20 minutes

  - platform: tod
    name: Event 2
    time: “sensor.match_time_two”
    before_offset: 15 minutes
    after_offset: 20 minutes

  - platform: tod
    name: Event 3
    time: “sensor.match_time_three”
    before_offset: 15 minutes
    after_offset: 20 minutes
sensor:
  - platform: template
    sensors:
      time_of_day:
        friendly_name: "Next event is”
        value_template: >-
          {% if is_state('sensor.match_time_one,'on') %}
            First Event  
          {% elif is_state('sensor.match_time_two,’on') %}
            Second Event 
          {% else %}
            Third Event
          {% endif %}

:pray:

thank for the reply, as I said that was not a code, just to demonstrate the idea

instead of a tod binary sensor you will likely need to create a template binary sensor to tell you you are in the window of each event.

post the state of your “match_time_one” sensor.

sensor.match_time_one output is 18:00

same thing with other sensors, just hours and minutes like 14:30

create a template binary_sensor (I’m using the legacy format here):

binary_sensor:
  - platform: template
    value_template: "{{ today_at(states('sensor.match_time_one')) - timedelta(minutes = 15) < now() < today_at( states('sensor.match_time_one') ) + timedelta(minutes = 20) }}"

that will be true 15 minutes before till 20 minutes after the “match_time_one”

1 Like

thanks that was really helpful and good start