-
Notifications
You must be signed in to change notification settings - Fork 58
-
Greetings! :)
Currently working on simple automation that updates the options of a my input_selector entity.
My automation looks like this:
automation:
- alias: "New wallpaper update"
trigger:
platform: event
event_type: folder_watcher
event_data:
event_type: created
action:
service: pyscript.update_wallpaper_options
data_template:
action: 'Add'
entity_id: input_select.wallpaper_selector
file: "{{ trigger.event.data.path }}"
While the pyscript service looks like this:
def update_wallpaper_options(action = None, entity_id = None, file = None):
"""Updates the list of wallpaper options each time a new file is added to the folder"""
if file != None:
file = file.split('/')[-1] #Get the file name (change background image already point to the correct path)
current_options = hass.states.get(entity_id).attributes['options'] #get the current options
if action == 'Add':
current_options.append(file) #Append the file name to the current options
service_data = {'entity_id' : entity_id, 'options': current_options}
hass.services.call('input_select', 'set_options', service_data) #call the service to update the options of the entity
From testing I know for a fact the last line is what is crashing home assistant
Additional information:
I'm using homekit-infused dashboard, which I have integrated using a package
My input_select config looks like this:
wallpaper_selector:
name: Wallpaper selector
options:
- Theme Wallpaper
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions
Is there a reason you're not using the pyscript versions of hass.states.get
and hass.services.call
? With the code you have above, it would just as easily run as a python_script
since you are using the hass internal methods instead of the pyscript methods and variables.
Replies: 1 comment 2 replies
-
Is there a reason you're not using the pyscript versions of hass.states.get
and hass.services.call
? With the code you have above, it would just as easily run as a python_script
since you are using the hass internal methods instead of the pyscript methods and variables.
Beta Was this translation helpful? Give feedback.
All reactions
-
I was using some other libraries which I needed pyscript for, what I showed was only a snipet of the code. In the meanwhile I have figured out the issue and fixed it, so you can close this question,
Regards
Beta Was this translation helpful? Give feedback.
All reactions
-
I can't close this question. But you can.
Beta Was this translation helpful? Give feedback.