Ad Widget

Collapse

Raspberry Pi 5 DHT11 using Virtual environment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The-Tech
    Junior Member
    • Jan 2022
    • 29

    #1

    Raspberry Pi 5 DHT11 using Virtual environment

    I am attempting to monitor temperature and humidity with Raspberry Pi 5 using a DHT11 sensor. My Pi is running Trixie ( 64bit) and I find that the only way to get the needed Library files and scripts to work is to now run them is using them in a Virtual environment. Using the command python3 -m venv env and then running the source env/bin/activate to activate the session. In this session I can run the needed script and get the results locally via ssh session. However, because it is running a virtual session my Zabbix agent does not seem to see the results. I am running an imported template, but I am not seeing any temperature and humidity results.

    I am somewhat new to Zabbix, so I am hoping that someone else has figured out where I am going wrong.

    I used the following steps, https://pimylifeup.com/raspberry-pi-install-lgpio/ and this worked well locally but I just can't figure out how to get Zabbix server to run the key for a VENV environment ( see attachment) I have several Pi's running the scripts on 32 bit bullseye fine, but they didn't need the Vir environment and I really can't keep running unsupported OS versions.

    I am sure there is a simple way to get Zabbix server to run VENV python scripts but I just can't figure out what I am doing wrong.


    zabbix_agentd.conf includes AllowKey=system.run[*]
    visudo includes

    # user privilege specification
    root ALL=(ALL:ALL) ALL
    pi ALL=(ALL:ALL) ALL
    zabbix ALL=(ALL:ALL) ALL




    VENV details

    /home/pi/dht/env/bin/python <== location of the Vir Environment Python
    /home/pi/dht/dht11.py <== Location of Python script


    my Zabbix Item
    system.run[sudo /home/pi/dht/env/bin/python /home/pi/dht/dht11.py 11 4]
    Attached Files
    Last edited by The-Tech; 08-12-2025, 22:38.
  • Viktors Fomics
    Member
    • Oct 2025
    • 42

    #2
    Hello

    Looks like access issues, zabbix user needs to have proper access to VENV. You can test it directly with
    sudo -u zabbix /home/pi/dht/env/bin/python /home/pi/dht/dht11.py 11 4
    and check if any access-related errors appear.

    Comment

    Working...