rkoshak/sensorReporter

GPIO Actuator always works in "TOGGLE" Mode, steady state output is not possible

darkogorgievski opened this issue · 6 comments

See issue title
In the readme file the TOGGLE is described as optional setting, but without it the sensor reporter logs an error.

Additionally maybe a good idea is to change the name of ÏnitialState" to "InvertOutput", which should create pulse with duration of 0,5s opposite on the "InitialState". For Example if the initial state is ON (because as in my case the relay board inputs are inverted), one might need to create pulse "ON-OFF-ON"

Config.ini:

[Logging]
 Syslog = YES
 Level = DEBUG

 [Connection1]
 Class = openhab_rest.rest_conn.OpenhabREST
 Name = openHAB
 URL = http://192.168.4.227:8080
 RefreshItem = RefreshSprinklers
 Level = DEBUG

 [Connection2]
 Class = mqtt.mqtt_conn.MqttConnection
 Name = MQTTSprinklers
 Client = rPiZero
 User = ****
 Password = ****
 Host = 192.168.4.227
 Port = 1883
 Keepalive = 10
 RootTopic = sensor_reporter
 TLS = NO
 Level = DEBUG

 [Sensor1]
 Class = heartbeat.heartbeat.Heartbeat
 Connection = MQTTSprinklers
 Poll = 60
 Num-Dest = heartbeat/num
 Str-Dest = heartbeat/str

 [Actuator0]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc  = SprinklersTerraceCmd
 InitialState = ON
 Pin = 26
 Level = DEBUG

 [Actuator1]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklersGardenHouseCmd
 InitialState = ON
 Pin = 19
 Level = DEBUG

 [Actuator2]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklersEntranceCmd
 InitialState = ON
 Pin = 13
 Level = DEBUG

 [Actuator3]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklersFrontCmd
 InitialState = ON
 Pin = 6
 Level = DEBUG

 [Actuator4]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = DripHoseCmd
 InitialState = ON
 Pin = 5
 Level = DEBUG

 [Actuator5]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinkerPumpCmd
 InitialState = ON
 Pin = 0
 Level = DEBUG

 [Actuator6]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklerPiRelay7Cmd
 InitialState = ON
 Pin = 11
 Level = DEBUG

 [Actuator7]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklerPiRelay8Cmd
 InitialState = ON
 Pin = 9
 Level = DEBUG

Log output:


 Dec 21 18:59:15 raspberrypizero INFO - [MqttConnection] Disconnected from MQTT broker with client <paho.mqtt.client.Client object at 0xb653d330>, userdata None, and code 0
Dec 21 18:59:15 raspberrypizero python3[5954]: /opt/sensor_reporter/gpio/rpi_gpio.py:140: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
Dec 21 18:59:15 raspberrypizero python3[5954]:   GPIO.setup(self.pin, GPIO.OUT)
Dec 21 18:59:15 raspberrypizero python3[5954]: Exception in thread Thread-1:
Dec 21 18:59:15 raspberrypizero python3[5954]: Traceback (most recent call last):
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
Dec 21 18:59:15 raspberrypizero python3[5954]:     self.run()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/lib/python3.7/threading.py", line 865, in run
Dec 21 18:59:15 raspberrypizero python3[5954]:     self._target(*self._args, **self._kwargs)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
Dec 21 18:59:15 raspberrypizero python3[5954]:     self.loop_forever(retry_first_connection=True)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self.loop(timeout, max_packets)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1181, in loop
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self.loop_read(max_packets)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self._packet_read()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self._packet_handle()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
Dec 21 18:59:15 raspberrypizero python3[5954]:     return self._handle_publish()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
Dec 21 18:59:15 raspberrypizero python3[5954]:     self._handle_on_message(message)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3429, in _handle_on_message
Dec 21 18:59:15 raspberrypizero python3[5954]:     callback(self, self._userdata, message)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/opt/sensor_reporter/mqtt/mqtt_conn.py", line 147, in on_message
Dec 21 18:59:15 raspberrypizero python3[5954]:     handler(msg.payload.decode("utf-8"))
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 159, in on_message
Dec 21 18:59:15 raspberrypizero python3[5954]:     self.cmd_src, msg, self.toggle, self.pin)
Dec 21 18:59:15 raspberrypizero python3[5954]: AttributeError: 'RpiGpioActuator' object has no attribute 'toggle'
Dec 21 18:59:15 raspberrypizero systemd[1]: sensor_reporter.service: Succeeded.
Dec 21 18:59:15 raspberrypizero systemd[1]: Stopped Reports status and sensor readings over MQTT and openHAB REST.
Dec 21 18:59:19 raspberrypizero systemd[1]: Started Reports status and sensor readings over MQTT and openHAB REST.
Dec 21 18:59:20 raspberrypizero INFO - [sensor_reporter] Setting logging level to DEBUG
Dec 21 18:59:20 raspberrypizero INFO - [sensor_reporter] Creating connection MQTTSprinklers
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Initializing MQTT Connection...
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Attempting to connect to MQTT broker at 192.168.4.227:1883
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Connection to MQTT is successful
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] LWT topic is sensor_reporter/status, subscribing to refresh topic sensor_reporter/refresh
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/refresh'
Dec 21 18:59:20 raspberrypizero DEBUG - [MqttConnection] Published message ONLINE to sensor_reporter/status retain=True
Dec 21 18:59:20 raspberrypizero DEBUG - [sensor_reporter] 1 connections created
Dec 21 18:59:20 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator0
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Connected with client <paho.mqtt.client.Client object at 0xb64e6330>, userdata None, flags {'session present': 0}, and result code 0. Subscribing to refresh command topic sensor_reporter/refresh
Dec 21 18:59:20 raspberrypizero DEBUG - [MqttConnection] Published message ONLINE to sensor_reporter/status retain=True
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] on_connect: Resubscribing to sensor_reporter/refresh
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Received a request for current sensor states before poll_mgr has been created, ignoring.
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 2
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 3
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 1, (0,)
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 4, (0,)
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersTerraceCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 5, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator0: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator0'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator1
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersGardenHouseCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 6, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator1: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator1'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator2
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersEntranceCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 7, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator2: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator2'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator3
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersFrontCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 8, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator3: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator3'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator4
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/DripHoseCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 9, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator4: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator4'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator5
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinkerPumpCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 10, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator5: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator5'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator6
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklerPiRelay7Cmd'
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator6: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator6'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 11, (0,)
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator7
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklerPiRelay8Cmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 12, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator7: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator7'
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] 0 actuators created
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Sensor1
Dec 21 18:59:21 raspberrypizero INFO - [Heartbeat] Configuing Heartbeat: msec to heartbeat/num and str to heartbeat/str with interval 60.0
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] 1 sensors created
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] Creating polling manager
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] Created, returning polling manager
Dec 21 18:59:21 raspberrypizero INFO - [PollManager] Starting polling loop
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 13
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] Published message 18 to sensor_reporter/heartbeat/num retain=False
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 14
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] Published message 00:00:00 to sensor_reporter/heartbeat/str retain=False
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 15
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] Published message 60122 to sensor_reporter/heartbeat/num retain=False
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 16
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] Published message 00:01:00 to sensor_reporter/heartbeat/str retain=False
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 17
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] Published message 120224 to sensor_reporter/heartbeat/num retain=False
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 18
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] Published message 00:02:00 to sensor_reporter/heartbeat/str retain=False

I thought I had replied to this earlier. I know I ran some tests.

First, open a separate issue for the invert stuff.

The error has nothing to do with the toggle parameter being optional. I think the problem is that warning about the channel already being in use at the top prevented the rest of the constructor from running and therefore the toggle property never got set.

There is not the "Configued RpoGpuiActuator: pin..." log line I would expect to be there. I've not been able to reproduce this error so I can't test this myself.

Another possibility is that the message came in on MQTT before the actuator was done being initialized but I don't think that's the case. I'm not seeing expected log statements that would indicate that either.

I have also the problem that the actuator always toggles using the rest API.

Digging in rpi_gpio.py I found line 149 seems to have a bug.
self.toggle = bool(params("Toggle"))
params() returns a string and bool() will convert any string to true, except an empty string. Following this definition of bool().

I guess the easiest fix would be to replace bool(params("Toggle")) with an compare params("Toggle").lower() == "true".
@rkoshak what do you think?

I guess the easiest fix would be to replace bool(params("Toggle")) with an compare params("Toggle").lower() == "true".
@rkoshak what do you think?

I'm not sure it I misunderstood something or this changed between Python 2 and Python 3. In either case, this isn't going to be the only place where a call to bool with a String like that is going to pop up. It'll need to be changed everywhere.

Based on my research, using https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool would be closest to my original intent. I was mainly looking for something that works similar to Ansible where you can use just about any "truthy" string and it will work. So it should be replaced with

bool(distutils.util.strtobool(params("Toggle").lower()))

I see!
If I understand you correct some of the code was intended to be used with python2, this would explain some other errors I had.
I'll dig for the other places of bool() and send a PR.

It was originally written in Python 2. The last rewrite moved from supporting both Python 2 and Python 3 to only support Python 3. But clearly some stuff remains. I'm limited in how much I can test lot of this due to lack of devices and such. I do my best but bugs will always come through.

I really appreciate the PR. Thanks!

Closed via PR #84