I built a Custom Input for the SI1145 IR / UV / Visible Light Sensor using the tsl2561 sensor as a template. I also riddled the SI1145 code with NOTES, for myself so I have an idea of what I did.
I’m trying to learn python the hard way, by reading and trying to program different modules. The tsl2561 had a lot of code in def get_measurement(self) that didn’t seem relevant for the SI1145 so I just commented the lines.
Mycodo excepted the code and when I go to the SETUP > INPUT I was able to add the SI1145 sensor and was even able to open the drop down. That is as far as I’ve gone. The last attempt with creating a Custom Input I corrupted the system so bad I had to re-load Mycodo.
Could someone take a look at the following code and tell me if it looks ok as is or did I miss a few things?
Thanks for sharing your Input module. Here are some things I noticed:
I see your module has a 5th measurement (prox, not sure what it is), but it’s not used (i.e. no value is saved to the database for that measurement). added “length” measurement and unit “cm” and added function to read proximity.
Also, I notice get_measurement() doesn’t actually do anything, so the module will not acquire or storing any measurements. The contents of get_lux() should be renamed get_measurement() or get_lux() should be called in get_measurement() (though redundant) if you want this to occur. get_measurement() should also return self.return_dict.
You’re calling _get_luminosity(), but this appears to be a protected member of the sensor class (indicated by the leading “_”). changed to use the functions specified in the library example script.
There doesn’t appear to be lux() in the module you are using. Removed.
You aren’t checking if all channels are enabled. Added.
Here’s an updated version with the changes for you to review/test: si1145.py (2.4 KB)
Kyle thanks for all your help. Hopefully by the time I get the whole system put together I’ll Have a better understanding of python.
the fifth measurement is for proximity. I found an option on the net where they added a diode to the sensor board. Supposedly it can measure out to 50 cm. I was hoping to use it for measuring how close the tegu’s get to the uv light and see if they have a preference to where they like to bask.
I do have some Ultrasonic Distance Sensors, but I planned to use them on the fogging units to measure the water in the holding tanks. but that’s a few weeks away.
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/controllers/base_controller.py”, line 74, in run
self.initialize_variables()
File “/var/mycodo-root/mycodo/controllers/controller_input.py”, line 317, in initialize_variables
self.measure_input = input_loaded.InputModule(self.input_dev)
File “/home/pi/Mycodo/mycodo/inputs/custom_inputs/si1145.py”, line 64, in init
self.initialize_input()
File “/home/pi/Mycodo/mycodo/inputs/custom_inputs/si1145.py”, line 71, in initialize_input
busnum=self.input_dev.i2c_bus)
TypeError: ‘module’ object is not callable
260 IR (Light) (SI1145 IR) CH2 | 2021/7/7 11:15:33
I didn’t activate / use the Proximity because it uses an IR LED, which I don’t have on hand. I’ll order a half dozen after lunch. But, I don’t expect them until the middle of the month… I’ll advise…
the other part I haven’t activated / use is the Lux. I’ll have to go back to my notes an see what they are doing and why…