The script looks like this (simple script for proof concept):
import datetime
with open(“resultatPython.txt”, ‘a’) as out:
out.write(datetime.datetime.now().str()+ ‘\n\n’)
But the file is not created at all, or script not executed:
But i can read:
2017-09-20 13:21:47 INFO (MainThread) [homeassistant.helpers.script] Script python script test: Executing step call service
If you’ve provided a direct copy/paste of your code, you appear to have indentation issues
Also your data_template appears to be missing some chars:it should look like:
import datetime
with open(“resultatPython.txt”, ‘a’) as out:
out.write(datetime.datetime.now().str()+ ‘\n\n’)
I was not questioning that part but the HA automation part as it sounds like it does not get triggered at all.
You may want to use syntax highlighting to write your code as it still doesn’t look right, Yaml is VERY strict with identations so an extra space and it won’t work
(there is no indentation before platform: and entity_id: underneath the trigger: line
To see if the automation is triggered or not, you can either add it to the front end and click on it, it will show you when it was last triggered, or you can use the template tab un dev tools and enter this: {{ states.automation.python_script_test.attributes.last_triggered }} and see if it gives you None (never ran) or an actual date.
you’d have to make sure you move the input_slider first to trigger the automation
Last thing I’m unsure of if the alias. I’d remove the single quotes and rename it into python_script_test
How i get to know which platform is needed to run a python script?, Also, where can i find a description of each available object at config?
Thanks
The template shows a date/time.
The scripts are located at:
Named:
/home/orangepi/.homeassistant/python_scripts/hello_world.py
/home/orangepi/.homeassistant/python_scripts/hello_world2.py
I run hass as root (to assure it can write to F.S.)
The actual configuration is:
automation:
alias: python_script_test
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
Good!
I’m just fighting with limitations.
It seems ‘include’ is not allowed, and subsequently i guess filesystem access is not possible.
I am working on an orangepi hardware, so, the access to gpio is done using a different object than raspberry pi, and is not available on python3: pyA20.gpio
So i am trying to run a python script to set the window blinds to a position set by a slider, but the parameter does not pass.
It seems Hass doesn’t process the brackets, thus the string after ‘:’ is directly sent to execution.
Already tried:
Single or double quoted everything, or no quotes:
Parameters:
0- /home/orangepi/.homeassistant/python_scripts/fesAmbTemps.py
1- {{
2- states.input_slider.ac_temperature.state
3- }}
(Please format your YAML correctly as explained in the large blue box at the top)
According to the documentation for the shell command, that does support templates. However, there the executa_python is the internal name for that command, so you need to name them all differently.
I know it can pass arguments, it works on bash scripts.
But it does not seems to work running python script, it doesn’t even run in any way, with or without parameters.
Seems the only way might be an sh script workarround, but NOT:
shell_command:
executa_python: ‘bash /home/orangepi/pythonBridge.sh /home/orangepi/.homeassistant/python_scripts/fesAmbTemps.py {{ states.input_slider.ac_temperature.state }}’
Doesn’t work anyways, it doesn’t even try?¿ Is there a security
I just wanted to create a custom window blinds with positioning using a slider on a orangepi, but is it possible? or i need another software?
If you don’t post correctly formatted YAML (again, see the big blue box) it’s hard for us to help. YAML requires correct formatting, including the number of spaces. Any mistake can be critical, and because you’re just pasting as text, it loses all that information.
I’d also check your logs, to see if there are error messages.
Oh, and your scripts do have the execute bit set (chmod a+rx /home/orangepi/pythonBridge.sh)?
Sorry about the formatting, the web forum editor won’t let me publish straight from the code (the dash sign messes all off, publishes a dot and a ‘lf’ ), and erases most of the spaces, but trust me, the yaml is valid.
How can i get a button to trigger a script for on and also for off?
It’s not hard - see the big blue box at the top that I’ve directed you to twice already, or if you’re in a hurry, just select the text you want to mark as code and push </> on the editing bar.
If you can do that, we can look at what you’re posting and possibly provide suggestions.
homeassistant:
# Name of the location where Home Assistant is running
name: Home
# Location required to calculate the time the sun rises and sets
# Impacts weather/sunrise data (altitude above sea level in meters)
elevation: 600
# metric for Metric, imperial for Imperial
unit_system: metric
# Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
time_zone: Europe/Madrid
#-------------------------------------barres de la esquerra
# Enables support for tracking state changes over time.
history:
# View all events in a logbook
logbook:
# Enables the frontend (la fila automations de la esquerra)
frontend:
# Enables configuration UI (fila config de la esquerra) <-- restart recarrega config
config:
logger:
default: info
#--------------------------------------------------------
http:
# Uncomment this to add a password (recommended!)
# api_password: PASSWORD
# Uncomment this if you are using SSL or running in Docker etc
# base_url: example.duckdns.org:8123
# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
#updater:
# Discover some devices automatically
#discovery:
# Show links to resources in log and frontend (el welcome de la principal)
#introduction:
# Allows you to issue voice commands from the frontend in enabled browsers
conversation:
# Track the sun (la rodona de dalt que ensenya el sol)
sun:
# Weather Prediction (rodona temps de dalt)
sensor:
platform: yr
# Text to speech
tts:
platform: google
python_script:
input_slider:
ac_temperature:
name: Valor Temperatura
initial: 5
min: 0
max: 10
step: 1
shell_command:
executa_python: '/home/orangepi/.homeassistant/python_scripts/fesAmbTemps.py {{ states.input_slider.ac_temperature.state }}'
executa_python2: '/home/orangepi/.homeassistant/python_scripts/fesAmbTemps.py {{ states.input_slider.ac_temperature.state }}'
set_ac_to_slider: '/home/orangepi/cosa.sh {{ states.input_slider.ac_temperature.state }}'
switch:
- platform: command_line
switches:
executar_comanda:
friendly_name: 'botons executen comanda'
command_off: bash /home/orangepi/cosa.sh apagat
command_on: bash /home/orangepi/cosa.sh enjegat
- platform: template
switches:
executar_comanda2:
value_template: "{{ is_state('switch.executar_comanda2', 'on') }}"
friendly_name: 'botons executen python'
turn_off:
- service: shell_command.executa_python2
entity_id: switch.dolenta
- service: variable.set_variable
data:
variable: test_timer
value_template: 'on'
turn_on:
service: shell_command.executa_python
entity_id: switch.bona
# value_template: "{% if is_state('switch.executar_comanda2', 'on') %}on{% else %}off{% endif %}"
# value_template: "{{ is_state('switch.executar_comanda2', 'on') }}"
#media_player:
# - platform: cast
camera:
- platform: generic
name: Plaça major de Vic
still_image_url: http://www.meteosona.cat/static/estacions/images/webcams/VicPlaca.jpg
- platform: local_file
name: Webcam USB
file_path: /home/orangepi/.motion/lastpicture.jpg
- platform: local_file
name: Gràfica ping
file_path: /home/orangepi/graph/resultat.png
automation:
- alias: 'Valor de slider a lampara'
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
service: shell_command.executa_python
- alias: 'Valor de slider a shell'
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
service: shell_command.set_ac_to_slider
- alias: python_script_test
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
- service: python_script.hello_world
data_template:
name: "Garfius"
dades: '{{states.input_slider.ac_temperature.state | int}}'
dades2: '{{states.input_slider.ac_temperature.state}}'
- alias: python_script_test-2
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
- service: python_script.hello_world2
data_template: {"name": "Garfius"}
#group: !include groups.yaml
#automation: !include automations.yaml
Back to the problem at hand, you said you want to be able to run the on and off scripts (command_on and command_off) by a toggle. Can you provide an image of what you’re referring to?
I just need a simple, non dependant, toggle switch able to fire a services( mostly scripts) when it’s turned on, and a different one when turned off. And of course i need the slider position value.