I’m trying to make a simple PID input/ouput app using Appdeamon 4
What I am trying to achieve is the following:
-
Input = ‘sensor.trv_zolder’ ( just a temperature sensor )
-
Output = ‘input_number.pid_test’( output value from PID controller which I need to control my boiler )
I’m using the following Python library ; https://github.com/m-lundberg/simple-pid
Since I don’t have any experience using Python ( only experience with programming in C/C++)i’m getting stuck.
This is app code
import appdaemon.plugins.hass.hassapi as hass
from simple_pid import PID
class PIDcalc(hass.Hass):
def initialize(self):
state= self.get_state("sensor.trv_zolder")
self.log(state)
inputset = state
pid = PID(5, 0.2, 0.0, setpoint=inputset)controlled_system
pid.sample_time = 10
#while True:
self.log(inputset)
output = pid(inputset)
self.log(output)
self.log("Setting pid.test to PID value")
self.set_state("input_number.pid_test",state=output)
The following error occurs in the log.
2020-12-03 20:32:40.454192 INFO AppDaemon: Terminating pid_control
2020-12-03 20:32:40.458250 INFO AppDaemon: Reloading Module: /config/appdaemon/apps/pid.py
2020-12-03 20:32:40.462907 INFO AppDaemon: Initializing app pid_control using class PIDcalc from module pid
2020-12-03 20:32:40.469306 INFO pid_control: 17.5
2020-12-03 20:32:40.473642 WARNING pid_control: ------------------------------------------------------------
2020-12-03 20:32:40.474324 WARNING pid_control: Unexpected error in worker for App pid_control:
2020-12-03 20:32:40.474972 WARNING pid_control: Worker Ags: {}
2020-12-03 20:32:40.475503 WARNING pid_control: ------------------------------------------------------------
2020-12-03 20:32:40.476966 WARNING pid_control: Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/appdaemon/app_management.py", line 150, in initialize_app
await utils.run_in_executor(self, init)
File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 290, in run_in_executor
response = future.result()
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/appdaemon/apps/pid.py", line 13, in initialize
output = pid(inputset)
File "/usr/lib/python3.8/site-packages/simple_pid/PID.py", line 88, in __call__
error = self.setpoint - input_
TypeError: unsupported operand type(s) for -: 'str' and 'str'
2020-12-03 20:32:40.477675 WARNING pid_control: ------------------------------------------------------------
It looks like the ‘state’ variable=( sensor.trv_zolder ) is not accepted somehow in the Pid controller library? Since making the variable just simply ‘10’ results in some output from the Pid
2020-12-03 20:32:40.477675 WARNING pid_control: ------------------------------------------------------------
2020-12-03 21:49:29.026334 INFO AppDaemon: Terminating pid_control
2020-12-03 21:49:29.034631 INFO AppDaemon: Reloading Module: /config/appdaemon/apps/pid.py
2020-12-03 21:49:29.040271 INFO AppDaemon: Initializing app pid_control using class PIDcalc from module pid
2020-12-03 21:49:29.053253 INFO pid_control: Previous message repeated 1 times
2020-12-03 21:49:29.054360 INFO pid_control: 17.0
2020-12-03 21:49:29.055422 INFO pid_control: 10
2020-12-03 21:49:29.056470 INFO pid_control: 0.0
2020-12-03 21:49:29.060139 INFO pid_control: Setting pid.test to PID value
Can anybody help me in the right direction? I’ve tried to follow from the appdeamon docs, however there are not any examples using external libraries.
Thanks,