Hi,
I have connected an MCP3008 ADC to my raspberry pi 3 in order to measure 8 analog sensors. I already have a simple python code, which can address every channel of the MCP3008 and get the sensor measurement.
I want also implement this feature to my home assistant system. For example an automation script should run the python script and get the sensor data from it. If the number is smaller than a certain value it should switch on one relay.
Can anyone help me with the implementation of my python script. I have no idea how to call its service and get the data from it?
Might want to try looking in to mqtt or aREST should be fairly simple to integrate into your python code. I don’t have any examples in Python though.
You can call your python code with a Command line sensor and get the values into HA.
That’s a good idea! I tried it, but it does not work properly. Do you have any suggestions why?
as I run the script manually it gives me the sensor output converted in %. But the command line sensor does not recognize the output value.
What kind of HA are you running?
On hass.io, the command line is very restricted.
If you’re on hassbian in a venv you first have to activate it and run the command as ha user.
Here are a few tips about it.
MQTT might also be an option.
I am using hassbian. So I tried to run the command as ha user and this is the result:
so, when I run it without sudo it can not load the spidev library and returns an error, but when it is rum with sudo, there is no problem.
The spidev library is installed also on the venv, but apparently hass does not have permissions to import it. Can I change that, because I think that is is not possible to run sudo command within the command line sensor?
Hola amigo, lograste incorporar el mcp3008 en home assitant???
It appears you are getting the voltage reading from the ADC. You may need to convert it. You can check the range of the ADC vs the least significant bit, to see if it’s in the range. You would then have to get python to do some math on it to get the value.
The ADC runs on a 3.3 or 5V supply, so I sure hope it isnt detecting 14.27V! The script should be returning a percentage of the reference voltage.
Also that post is 3 years old lol.
Sorry, I meant the ADC converted output. Whatever the range of the analog device. And ya, that’s old. I just saw the Jun posts date. Is there a completed thread about ADC’s?
What did you end up doing?