For a very long time I was using the date to identify US Holiday scenes and used select_option from a input_select list that I had generated. Every morning I’d run a ‘check_holiday’ script which compares the present date with an if-else tree. However, it appears that after I have updated to the latest “dated” HassIO versions it appears that I am no longer able to use scripts or automation to get back to the “None” state.
I feel that I have tried everything. Also, considering that it worked perfectly in the past. Any guidance would be appreciated.
input_select:
holiday:
name: Holiday Lighting
options:
- "None"
- Valentine's Day
- St. Patrick's Day
- Independence Day
- Halloween
- Thanksgiving
- Christmas
automation:
## Holiday Lights
- alias: "Determine Holiday"
trigger:
- platform: time
at: '0:00:01'
- platform: event
event_type: homeassistant_start
action:
- service: script.holiday
scripts:
'holiday':
alias: Check Holiday
sequence:
- service: input_select.select_option
data_template:
entity_id: input_select.holiday
option: >
{% if (now().month==2 and now().day<=14) %}
Valentine's Day
{% elif (now().month==3 and now().day>=7 and now().day<=17) %}
St. Patrick's Day
{% elif (now().month==7 and now().day<=4) %}
Independence Day
{% elif (now().month==10)%}
Halloween
{% elif (now().month==11 and now().day<=26) %}
Thanksgiving
{% elif ((now().month==11 and now().day>26) or (now().month==12 and now().day<=25)) %}
Christmas
{% else %}
'None'
{% endif %}
I have vetted all of the sections of code, it is only the template for option: > that is failing when using “None”. I have tried with single-quote, double-quote, no-quote - still nothing.
Error messages variations I have seen:
`Check Holiday: Error executing script. Invalid data for call_service at pos 1: string value is None for dictionary value @ data['option']`
&
`Check Holiday: Error executing script. Invalid data for call_service at pos 1: string value is "None" for dictionary value @ data['option']`
Change the input_select’s option from "None" to "none" and then change the script’s final entry from 'None' to none and that will fix it (tested and confirmed on my system).
input_select:
holiday:
name: Holiday Lighting
options:
- "none"
- Valentine's Day
- St. Patrick's Day
- Independence Day
- Halloween
- Thanksgiving
- Christmas
automation:
## Holiday Lights
- alias: "Determine Holiday"
trigger:
- platform: time
at: '0:00:01'
- platform: event
event_type: homeassistant_start
action:
- service: script.holiday
scripts:
'holiday':
alias: Check Holiday
sequence:
- service: input_select.select_option
data:
entity_id: input_select.holiday
option: >
{% if (now().month==2 and now().day<=14) %}
Valentine's Day
{% elif (now().month==3 and now().day>=7 and now().day<=17) %}
St. Patrick's Day
{% elif (now().month==7 and now().day<=4) %}
Independence Day
{% elif (now().month==10)%}
Halloween
{% elif (now().month==11 and now().day<=26) %}
Thanksgiving
{% elif ((now().month==11 and now().day>26) or (now().month==12 and now().day<=25)) %}
Christmas
{% else %}
none
{% endif %}
Although unrelated to the problem, you can now replace data_template with data because data_template was deprecated several versions ago.
EDIT
Correction. Removed quotes from the word none in the script.
Oops!, Sorry, I double-checked my own work and the script contained none not 'none'. Sorry about that. I’ve updated my previous post.
There was a change made, several versions ago, where templates can produce a value whose type is no longer restricted to being a string. This is known as ‘templates support native types’.
The way it works is that Home Assistant looks at the template’s final result and infers the value’s type. For example if the template generates this:
['cat', 'bat', 'rat']
it will be automatically handled as a list (not a string).
I believe what may be happening here is that “None” is the word that represents an empty value. In other words, “None” has special meaning so when your template generated it, Home Assistant inferred its meaning to be not the string “None” but the representation for an empty value. That’s why the error message complained that None was not a valid choice in your input_select (because it was not handling None as a string). In contrast, “none” is inferred to be a string value and not something else.
You stumbled upon one of several “side-effects” of the ‘native types’ enhancement. One of the other ones is where a template produces a string that looks like a hex value. Maybe you wanted it to be handled as a string but, because it looks like a hex value, its handled like a number.