jcreynolds
(James C. Reynolds II)
December 6, 2017, 4:15am
1
I have a sensor template I am creating to track details about sports teams.
platform: template
sensors:
cavs_opponent:
friendly_name: 'Opponent'
value_template: '{{ states.calendar.cavs_united_states.attributes.message }}'
cavs_starttime:
friendly_name: 'Start Time'
value_template: '{{ states.calendar.cavs_united_states.attributes.start_time }}'
cavs_channel:
friendly_name: 'Channel'
value_template: '{{ states.calendar.cavs_united_states.attributes.location }}'
I want to parse attributes, for example:
Opponent Kings
Start Time Date, Time(CST)
Status Home or Away(Not pictured, depends on parsing attributes, if Opponent contains VS then Home else if Opponent contains @ then Away)
Channel: Fox Sports Ohio
Any tips are appreciated.
jcreynolds
(James C. Reynolds II)
December 6, 2017, 10:01pm
2
Got this working finally found that right syntax for this. Posting here for anyone else who is trying to do the same thing.
platform: template
sensors:
cavs_opponent:
friendly_name: 'Opponent'
value_template: '{{ states.calendar.cavs_united_states.attributes.message.split(" ")[2] }}'
cavs_homeaway:
friendly_name: 'Playing at'
value_template: >-
{% if is_state('states.calendar.cavs_united_states.attributes.message.split(" ")[1]', 'vs') %}
Home
{% else %}
Away
{% endif %}
cavs_starttime:
friendly_name: 'Start Time'
value_template: '{{ states.calendar.cavs_united_states.attributes.start_time }}'
cavs_channel:
friendly_name: 'Channel'
value_template: '{{ states.calendar.cavs_united_states.attributes.location.split("Watch on ")[1] }}'
1 Like