Hello,
How do I use the variable with name hours? Thank you.
Error ERROR (MainThread) [homeassistant.core] Invalid service data for input_boolean.turn_on: Entity ID is an invalid entity id for dictionary value @ data['entity_id']. Got ''
script_hours:
sequence:
- service: input_boolean.turn_on
data_template:
entity_id: >
{% set original ="{{ hours }}" %}
{% set space = original.replace(' ', '') %}
{% set right_bracket = space.replace('[', '') %}
{% set final_hours = right_bracket.replace(']', '') %}
{% for word in final_hours.split(',') %}
{%- if '3' in word -%}
input_boolean.statusboiler
{%- endif -%}
{% endfor %}
you could also just replace everything at once unless you are trying to keep the lines shortâŚ
Itâs not any âbetterâ, just easier to read.
{% for word in hours.replace('[','').replace(']','').replace(' ','').split(',') %}
{%- if '3' in word -%}
input_boolean.statusboiler
{%- endif -%}
{% endfor %}
Not knowing the full context, an easy way would be to create a âdummyâ input_boolean that you donât actually use for anything or show in the frontend. Then, if the value of hours doesnât lead to a desired input_boolean, you could have it turn on the dummy one. E.g.:
{% for word in hours.replace('[','').replace(']','').replace(' ','').split(',') %}
{%- if '3' in word -%}
input_boolean.statusboiler
{%- else -%}
input_boolean.dummy
{%- endif -%}
{% endfor %}
Eh, there are ways of getting that, but it wouldnât be a script it would be a template sensor. Then youâd run into issues using the now() function because it doesnât update template sensors.
To get the template sensor working, youâd need to use the datetime sensor platform:
with this in your sensor config (Remember, youâd need to combine this with your existing sensor section, and combine the platform:templates with your existing platform: templates):