I have a sensor that was programmed by a very smart member in appdeamon. It reads the schedule from the cleveland browns web site and lets me know when the next game is on, the time and the channel it will air on.
also the opponent that we face.
everything seems to be working from the awesome sensor.
Now I need to know if anybody has any ideas on how to extract the information from the sensor so I can set automations (turn the tv to the specific station a few minutes before kick off and run some already configured automations before the game.
I assumed the sensor was called “sensor.next_game_from_cleveland_browns” and I’m not sure if you need to use all lower case in the attributes key or not. If it doesn’t work as posted then try that.
The date & time is a little trickier since it doesn’t have a standard key:value pair like the other two.
I tried to do that with another custom component and I could never work it out.
If you do figure out a way to pull that value then please let me know. And if I figure it out then I’ll post it back here.
So upon further reading, it seems like I will need to make a template sensor to pull and name the attributes I’m looking for so I can set the automation to create actions based on those attributes. Is that correct?
You could go with just the time module, but then the automation could fire every day. Best to go with the date_time module to include today into the mix.
Next you’ll need to make a template sensor. Now typically you’d have to make an on/off for the time of the event and a sensor for which channel. But we can combine them into a single sensor that displays off when off, and channel when on.
sensor:
- platform: template
sensors:
next_game:
value_template: >
{% set game_time_string = states('sensor.next_game_from_cleveland_browns') %}
# You may need to change Channel string to lowercase.
{% set game_channel = state_attr('sensor.next_game_from_cleveland_browns','Channel') %}
{% set current_time_string = states('time.date__time') %}
# the next 3 variables are in seconds.
{% set five_minutes = 5 * 60 %}
# set time for 5 minutes before game.
{% set game_time = as_timestamp(strptime(game_time_string,'%Y/%m/%d %H:%M:%S')) - five_minutes %}
{% set current_time = as_timestamp(strptime(game_time_string,'%Y-%m-%d %H:%M:%S')) %}
{% set game_end = game_time + five_minutes + 3 * 60 * 60 %}
{{ game_channel.lower() if game_time <= current_time <= game_end else 'off' }}
So this sensor will be equal to the lowercase channel name for 3 hours and 5 minutes, starting 5 minutes before the game. All other times, it will have a state of off.
Then with this automation:
- alias: Turn on the Game
trigger:
- platform: state
entity_id: sensor.next_game
condition:
- condition: template
value_template: "{{ trigger.to_state.state != 'off' }}"
action:
- service_template: "script.{{ trigger.to_state.state }}"