Hi, I am trying to write a custom rest sensor that tells me if it is a public holiday. I am basically wanting to a have a default value of 0. The sensor calls an api that gets all the public holidays. The sensor loops around the values and checks if the date is the same as today and if it is sets the flag to 1.
This works but I can’t figure out how to get the default value returned . At the moment I just get the default even though the check does set the variable to 1. This is my code (updated for developer console). Feels like I am using the variable wrong.
{% set value_json =
{"meta":{"code":200},"response":{"holidays":[
{"name":"New Year's Day","description":"New Year\u2019s Day is a public holiday in New Zealand on January 1 each year.","country":{"id":"nz","name":"New Zealand"},"date":{"iso":"2022-05-08","datetime":{"year":2022,"month":1,"day":1}},"type":["National holiday"],"locations":"All","states":"All"},
{"name":"New Year's Day","description":"New Year\u2019s Day is a public holiday in New Zealand on January 1 each year.","country":{"id":"nz","name":"New Zealand"},"date":{"iso":"2022-01-01","datetime":{"year":2022,"month":1,"day":1}},"type":["National holiday"],"locations":"All","states":"All"}
]}} %}
{% set public_holiday = 0 %}
{% if value_json is defined and value_json.response is defined %}
{% for entry in value_json.response.holidays if entry.date.iso == now().date() | string and now().hour | string in '1, 2, 3, 4' %}
{% set public_holiday = 1 %}
{% endfor %}
{% endif %}
{{ public_holiday }}