If you’re trying to run a Python script from either of the SSH addons, you can’t do that. If you want to run python scripts via HA, you can either using the python_script: integration here, use AppDaemon, or create a custom component.
What I am trying is pretty simple. See below.
I have a shopping list saved in the ‘.shopping_list.json’ file and I need to parse that and send me by a telegram notify.
action:
- service: notify.telegram_to_me
data_template:
message: >
Your Shopping List. {{ states('sensor.shopping_list.attributes.name') }}
'{{states.sensor.lista_de_compras.state}}'
{% for item in states.sensor.shopping_list.attributes.name %}
- {{ item.name }}
{%- endfor -%}
shopping_list.py
#!/usr/local/bin/python
# coding: utf8
import json
with open('/config/.shopping_list.json') as data_file:
shoppingListData = json.load(data_file)
content = u"Lista de Compras:\n"
for entry in shoppingListData:
if not entry['complete']:
content += u"- %s\n" % entry['name']
content += u"\n"
print(content)
The problem: the notification never arrive.
If I remove the for loop from the message and change by a simple text the notification normally arrives to me.