nielsfaber / scheduler-component

Custom component for HA that enables the creation of scheduler entities
GNU General Public License v3.0
631 stars 41 forks source link

Service to enable/disable/run a schedule providing the entity the schedule is related for. #371

Open mobilifone opened 1 month ago

mobilifone commented 1 month ago

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

github-actions[bot] commented 1 week ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

mobilifone commented 1 week ago

is not stale. Still active :-)