I’ve got a working pyscript script tied to an automation that processes items in a todo list and reads out a summary on the Voice satellite. In the interest of keeping things organized, I’ve got the .py file in a subfolder below pyscript/scripts
. As I said, so far everything is working.
However, for organization and learning things I’ll want to know for more complex tasks, I want to put the id of the todo list in a config, as that’s the kind of thing that probably shouldn’t be hard coded.
However, I’m having a heck of a time figuring out how to do that. I’ve got a strong software development background, just not with python, so some of it’s quirks are a mystery to me.
I’ve followed the directions in the pyscript docs and put pyscript: !include pyscript/config.yaml
in the master configuration.yaml, and in the referenced pyscript/config.yaml
I’ve got the apps
section with the name of the script and the setting I want to pass in.
However, within the script file, no matter what I do, it doesn’t recognize pyscript.app_config
. The documentation states
Note that
pyscript.app_config
is not defined in regular scripts, only in each application’s main file.
But, not being super familiar with python, I have no idea what that means. The “Advanced Topics” section of the docs there is finally an example of accessing the app_config with…
for inst in pyscript.app_config:
setup_triggers(**inst)
But that’s way more complicated than what I’m trying to do. I just want to set a string value in the config file to be used in the script.
Anybody know what the proper way to do this is? Thanks!
ETA, here’s my script, with the line I want to modify commented.
@service()
def summarizedWeatherAlerts():
import json
# I want to pull this value from the config #########
to_do_list_id = "todo.weather_alerts"
######################################################
summarized_alerts = []
for alert in todo.get_items(entity_id=to_do_list_id, status=['needs_action'])[to_do_list_id]['items']:
parsed_description = json.loads(alert["description"])
summarized_alerts.append(f"{parsed_description['Event']}. {parsed_description['Headline'].lower()}. ")
return { "text": "Next Alert. ".join(summarized_alerts) + " End of Weather Alerts" }