ok, I think I must be missing something obvious here.
I’m using hassbian and running a few python scripts by using the shell_command component, it uses three times the same python script but with a different argument coming from the userinterface.
shell_command:
set_temp_high: ‘python3 /home/homeassistant/.homeassistant/python_scripts/set_temperature.py -t {{ states.input_number.slider_day.state }}’
set_temp_low: ‘python3 /home/homeassistant/.homeassistant/python_scripts/set_temperature.py -t {{ states.input_number.slider_night.state }}’
set_temp_now: ‘python3 /home/homeassistant/.homeassistant/python_scripts/set_temperature.py -t {{ states.input_number.slider1.state }}’
This is all working fine (added the script as a reference below), however I wanted to add some robustness to make sure no multiple entries would be made at the same time to the communication bus of the heater.
Here I found the interesting python module ilock which seems to do what it should do (installed through ssh’ing to the pi and executing pip3 install ilock
). i.e. When I start several times the same script from the terminal window it just waits till the other one is finished.
However when executing this from home assistant, it fails at the line from ilock import ILock
, so it doesn’t look like ilock
is known by home assistant.
It sounds like I’m missing something very fundamental here … , any guidance?
thanks in advance!
import subprocess
import time
import getopt
import sys
#from ilock import ILockcheck if passed options are valid
try:
options, args = getopt.getopt(sys.argv[1:], ‘t:’,[‘temperature_setpoint=’])
print(options)
print(args)
except getopt.GetoptError:
print(“incorrect syntax”)
print(“usage: python3 set_temperature.py -t ”)
print(“default to 12 degrees”)
msg2=12
sys.exit(2)
for opt, value in options:
if opt in (‘-t’,‘-T’,‘–temperature_setpoint’):
msg2=value
print(“successful argument”)
print(msg2)#with ILock(‘ebus’, timeout=200):
msg1="ebusctl write -c f37 Hc1DayTemp "
cp = subprocess.run([msg1+msg2],shell=True,stdout=subprocess.PIPE)msg1="ebusctl write -c f37 Hc1NightTemp "
cp = subprocess.run([msg1+msg2],shell=True,stdout=subprocess.PIPE)time.sleep(30)
#check if it is truly set
cp = subprocess.run([“ebusctl read Hc1DayTemp”],shell=True,stdout=subprocess.PIPE)
temp=cp.stdout
if int(float(temp[0:4]))!=int(float(msg2)):
# if not set correct
msg1="ebusctl write -c f37 Hc1DayTemp "
cp = subprocess.run([msg1+msg2],shell=True,stdout=subprocess.PIPE)cp = subprocess.run([“ebusctl read Hc1NightTemp”],shell=True,stdout=subprocess.PIPE)
temp=cp.stdout
if int(float(temp[0:4]))!=int(float(msg2)):
# if not set correct
msg1="ebusctl write -c f37 Hc1NightTemp "
cp = subprocess.run([msg1+msg2],shell=True,stdout=subprocess.PIPE)
else:
print(“setting correct”)