Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Having trouble with the hass.services.call function on pyscript #224

Answered by dlashua
zroger49 asked this question in Q&A
Discussion options

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

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
2 replies
Comment options

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

Comment options

I can't close this question. But you can.

Answer selected by craigbarratt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /