[ ] I checked for similar existing requests (both open and closed) before posting.
[x] My request is generic, other users may benefit from it too.
Proposal
I had to enable or disable a schedule having only an entity name embedded in the schedule (maybe belonging to several schedules) so I had to write a script doing the job identifying, in the first step, the schedules where the entity is involved and then, in the second step, switch on/off/run according the case. If it could be possible, seems to me easier, to implement natively instead to use a script (Jinja coded not always easy to understand)
Example:
{% set target = 'the.entity.you.are.looking.for' %} {% set data = namespace(jobs=[]) %} {% set i = 0 %} {% set my_list = states.switch | selectattr('object_id', 'match', 'schedule')| map(attribute='entity_id') | list %} {% for sched in my_list %} {% if target in state_attr(sched,'entities') %} {% set data.jobs = data.jobs + [sched] %} {% set i = i + 1 %} {% endif %} {% endfor %} {{ data.jobs }}
The initial 'target' variable contains the entity name and, at the end, the result will be a list ('data.jobs') containing the entities name of the schedules involved.
Then I iterate in the list to on/off/run the schedules involved.
Checklist
Proposal
I had to enable or disable a schedule having only an entity name embedded in the schedule (maybe belonging to several schedules) so I had to write a script doing the job identifying, in the first step, the schedules where the entity is involved and then, in the second step, switch on/off/run according the case. If it could be possible, seems to me easier, to implement natively instead to use a script (Jinja coded not always easy to understand) Example:
_service: scheduler.turn_onforentity data: entity: my.appliance.entity
_service: scheduler.turn_offforentity data: entity: my.appliance.entity
_service: scheduler.run_action_forentity data: entity: my.appliance.entity skipconditions: false
Additional info
This is the Jinja fragment I used to:
{% set target = 'the.entity.you.are.looking.for' %} {% set data = namespace(jobs=[]) %} {% set i = 0 %} {% set my_list = states.switch | selectattr('object_id', 'match', 'schedule')| map(attribute='entity_id') | list %} {% for sched in my_list %} {% if target in state_attr(sched,'entities') %} {% set data.jobs = data.jobs + [sched] %} {% set i = i + 1 %} {% endif %} {% endfor %} {{ data.jobs }}
The initial 'target' variable contains the entity name and, at the end, the result will be a list ('data.jobs') containing the entities name of the schedules involved. Then I iterate in the list to on/off/run the schedules involved.
Thanks Dario