I’m still pretty new to HA but I’m trying to send the input_slider values to a python script. With this python script I’m able to change the RGB values of a LED. Currently it’s set to a fixed value so you can it a scene.
platform: command_line
switches:
ledstrip:
command_on: python /var/opt/homeassistant/test.py 0 2000 4095 --> thes values should come eventually from a slider change.
command_off: python /var/opt/homeassistant/uit.py
automation config.
alias: dim licht
trigger:
platform: state
entity_id: input_slider.slider2
action:
service: notify.Glenn
data:
message: {states.input_slider.slider2} --> was trying to see if I can send the state value with pushbullet
title: “test2”
So I want smooth change of the RGB LED with a slider value change and this togehter with a pyton script;
The script reads 6 values from topic home/milights/milight3 and prints them.
I made this with snippets from googling and try and error.
Maybe anyone knows a better way.
I think you just need to add .state to your sliders …
so …
message: {states.input_slider.slider2.state}
same thing for your python commands…
command_on: ‘python /var/opt/homeassistant/test.py 0 {{states.input_slider.slider1.state}} {{states.input_slider.slider2.state}}’
You may not need two {{}} round each state and you may not need the single quote round the whole line, but it works for me
I think I modified it but I’m not sure when the script will be called and if need to change the topic as well. Is there also a change in the configuration.yaml?
once again I’m new to this so sorry if I’m asking strange questions.
I’m one step further thanks btw but I think you misunderstood my question. I do not want to run the script on a slider change but I want to send the state value of the slider to my python script. I have 3 sliders that stands for the 3 colors in my strip.
I’m able to send the input_Slider value to my phone with pushbullet, I already think this a pretty big achievement .
Code:
- alias: dim licht Groen message
trigger:
- platform: state
entity_id: input_slider.slider2
action:
service: notify.Glenn
data:
message: '{{states.input_slider.slider2.state}}'
title: "slider"
Thanks again, I do understand the script and also the config in the automation but I hope you can guide me once more (sorry for the stupid questions)
I modified the script a little to get it work:
automation.yaml
- alias: dim licht Groen message
trigger:
- platform: state
entity_id: input_slider.slider2
action:
service: mqtt.publish
data_template:
topic: dev/test/slider2
payload_template: '{{states.input_slider.slider2.state | int }}'
retain: true
script:
#!/usr/bin/python
import paho.mqtt.client as paho
import paho.mqtt.publish as publish
topic = "dev/test/slider2"
def on_connect(client, userdata, flags, rc):
client.subscribe(topic + "/#")
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
#with the msg.payload you can control the LED
client = paho.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 60)
client.loop_forever()
But if I run it in the terminal of the PI it stays empty even when I move the slider. The script is saved in the same folder as where the configuration.yaml is saved (if it matters)
one small note:
This is my setup of the mqqt broker in configuration.yaml:
Sorry, why not just have an automation that calls the python script anytime the slider value changes? And pass the slider value to the script. If you want more info let me know…
Thanks it works but actually I want to send 3 values for 1 it works or for 3 also but then the value is coming from the same slide. Do I need to make 3 shell commands for it ?
automation.yaml
- alias: dim licht Rood message
trigger:
- platform: state
entity_id: input_slider.slider1
action:
service: shell_command.call_script
data_template:
rood: '{{states.input_slider.slider1.state | int}}'
- alias: dim licht Groen message
trigger:
- platform: state
entity_id: input_slider.slider2
action:
service: shell_command.call_script
data_template:
groen: '{{states.input_slider.slider2.state | int}}'
- alias: dim licht Blauw message
trigger:
- platform: state
entity_id: input_slider.slider3
action:
service: shell_command.call_script
data_template:
groen: '{{states.input_slider.slider3.state | int}}'
If I do that my home assistant is not reachable anymore. --> sorry made a typo, it works
- alias: dim licht
trigger:
- platform: state
entity_id: input_slider.slider1
- platform: state
entity_id: input_slider.slider2
- platform: state
entity_id: input_slider.slider3
action:
service: shell_command.call_script
data_template:
rood: '{{states.input_slider.slider1.state | int}}'
groen: '{{states.input_slider.slider2.state | int}}'
blauw: '{{states.input_slider.slider3.state | int}}'
Thank you all, I’ll post later my configuration to maybe help others and maybe some people have better ideas how to this nevertheless I still want to use MQTT. So Rainer thnks for the help I do understand more how it works and will use this for my sensor setup.