Inverser
(Inverser)
June 23, 2017, 4:26am
1
Hi, i need to pass value into the python script.
shell_command.dosomething works with the value 3.
But it doesn’t work if the value is from the service data: shell_command.dosomething2
Any one have any idea why. Please advise. Thank you!
shell_command:
dosomething: python \.homeassistant\python\dosomething.py 3
dosomething2: python \.homeassistant\python\dosomething.py {{ states.input_slider.ac_temperature.state | int }}
automation:
- alias: run_set_ac
trigger:
platform: state
entity_id: input_slider.ac_temperature
action:
service: shell_command.dosomething2
input_slider:
ac_temperature:
name: A/C Setting
initial: 1
min: 1
max: 30
step: 1
Hi @Inverser , have you tried it with quotes?
dosomething2: 'python \.homeassistant\python\dosomething.py "{{ states.input_slider.ac_temperature.state }}"'
I think you don`t need to convert to int.
I have this working:
record_sensors:
python /home/homeassistant/.homeassistant/includes/shell_scripts/sensors2file.py {{sensor01}} {{sensor02}} {{sensor03}} {{sensor04}}
and the relevant part in automations.yaml file:
- id: id015
alias: 'Record sensors to local file'
trigger:
platform: time
minutes: '/15'
seconds: 00
action:
- service: shell_command.record_sensors
data_template:
sensor01: '{{states.sensor.dark_sky_temperature.state | float}}'
sensor02: '{{states.sensor.temperature_sensor_1_1.state | float}}'
sensor03: '{{states.sensor.sonoff_01_power.state | float}}'
sensor04: '{{states.binary_sensor.door_sensor_2_0.attributes.battery_level | float}}'
HOWEVER, if the solution posted by @VDRainer works, it is definitely much simpler.
Good luck!
Inverser
(Inverser)
June 23, 2017, 1:09pm
4
Hi VDRainer, thanks for the reply.
I tried what you suggested but still doesn’t work…
keithh666
(Keith Hull)
June 23, 2017, 4:51pm
5
looks like the path is wrong to me if on pi it should be something like…
./home/pi/homeassistant/.homeassistant/python/dosomething.py ?
if in windoze again you will need the full path.
you also may have to use the full path to python
What is returned when you copy the template in Developer Tools/Templates?
Have you already tried it with convert to int?
Maybe i was wrong with this.
Or maybe try the solution of @timseebeck .
For me, this works:
set_hyperion_effect: 'scripts/hyperion_effect.sh "{{ states.input_select.hyperion_effect.state }}"'
Bash an input_select, but that should be the same.
Inverser
(Inverser)
June 24, 2017, 1:34pm
7
Got it to work. Just change to forward slash rather than using backslash…
Thanks for your help!
Inverser
(Inverser)
June 24, 2017, 1:35pm
8
Thanks for the help!
Didn’t notice I’m using the wrong slash…
Inverser
(Inverser)
June 24, 2017, 1:36pm
9
You are right! Thank you!