Integration of a DHT22 sensor - error in event.log: /usr/bin/env: python3 No such file or directory

  • Platform information:

    • Hardware: Raspberry Pi 3 B+
    • OS: Openhabian (am 5.Juni 2020 heruntergeladen), aber online Upgedatet
  • Ich will einen DHT22 Temperatur und Luftfeuchtigkeitssensor nach einer älteren Anleitung in openHAB einbinden.

Adafruit_DHT habe ich heruntergeladen und installiert

In Python3 kann ich auch nach einem
import Adafruit_DHT
den Befehl “Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 23)” ausführen
und erhalte Luftfeuchtigkeit und Temperatur zurück: (60,7…, 22,6…)
(statt der Punkte kommen viele Nachkommastellen)

Ich schreibe in /etc/openhab2/scripts eine Beginn --------------------------------------
#!/usr/bin/env python3

-- coding: utf-8 --

import Adafruit_DHT
import sys, time


DHT_PIN = 23 # GPIO nr

if name == ‘main’:
if len(sys.argv) > 1:
call = sys.argv[1].lower()

    if call == 'temperature':
        temperature = None
        while temperature == None:
            _, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
            if temperature == None:

    elif call == 'humidity':
        humidity = None
        while humidity == None:
            humidity, _ = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
            if humidity == None:
        print(humidity) Ende-------------------------------------
natürlich setze ich das Ausführen-Flag über chmod +x
ich kann nun folgenden Befehl eingeben:

python3 temperature
und erhalten die Temperatur: 24,…

Ich erstelle eine weatherstation.sitemap:
// Name of file and name of sitemap has to be the same
sitemap weatherstation label=“Raspberry Pi Wetterstation”
Frame label=“Innentemperatur” {
Text item=Weatherstation_Temperature
Text item=Weatherstation_Humidity
Frame {
Switch item=Weatherstation_Chart_Period mappings=[0=“1h”, 1=“4h”, 2=“8h”, 3=“12h”, 4=“24h”]
Chart item=Weatherstation_Chart period=h refresh=60000 visibility=[Weatherstation_Chart_Period==0, Weatherstation_Chart_Period==“Uninitialized”]
Chart item=Weatherstation_Chart period=4h refresh=60000 visibility=[Weatherstation_Chart_Period==1]
Chart item=Weatherstation_Chart period=8h refresh=60000 visibility=[Weatherstation_Chart_Period==2]
Chart item=Weatherstation_Chart period=12h refresh=60000 visibility=[Weatherstation_Chart_Period==3]
Chart item=Weatherstation_Chart period=D refresh=60000 visibility=[Weatherstation_Chart_Period==4]
----------------------------weatherstation.sitemap— Ende------------------------------------

Auch eine weatherstation.item erstelle ich:


Group Weatherstation_Chart (System, Charts)
Number Weatherstation_Chart_Period “Periode” (System)
Number Weatherstation_Temperature “Temperatur [%.1f °C]” (Weatherstation_Chart)
Number Weatherstation_Humidity “Luftfeuchtigkeit [%.1f %%]” (Weatherstation_Chart)

String temperature_out { channel=“exec:command:weatherstation_temperature:output” }
String humidity_out { channel=“exec:command:weatherstation_humidity:output” }

--------------------weatherstation.item ---- Ende--------------------

und ich erstelle eine Thing-Datei:

------------------weatherstation.things ---- Beginn----------------------------
Thing exec:command:weatherstation_temperature “Temperatur” [command="/etc/openhab2/scripts/ temperature", transform="REGEX((.*?)), interval=60, timeout=10, autorun=true]

Thing exec:command:weatherstation_humidity “Luftfeuchtigkeit” [command="/etc/openhab2/scripts/ humidity", transform=“REGEX((.*?))”, interval=10, timeout=10, autorun=true]


Ich erstelle eine persistence\rrd4j.persist Datei

------------------rrd4j.persist Beginn------------------------------
Strategies {
// for rrd charts, we need a cron strategy, every Minute is a must have.

everyMinute : "0 * * * * ?"

// get the data reduced for older values to keep database small

everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"

default = everyChange


Items {
// additionally persist Item
Weatherstation_Chart* : strategy = everyUpdate, everyMinute

und erstelle eine weatherstation.rules:

-----------------Beginn weatherstation.rules---------------------------------
rule “Weatherstation Temperature”
Item temperature_out received update
(( Float::parseFloat(temperature_out.state.toString) as Number ) * 10) / 10


rule “Weatherstation Humidity”
Item humidity_out received update
(( Float::parseFloat(humidity_out.state.toString) as Number ) * 10 ) / 10
------------------------------weatherstation.rules — Ende----------------------------------------

Das erste Problem ist im openhab.log:
2020-07-01 14:47:12.369 [WARN ] [ng.exec.internal.handler.ExecHandler] - Tried to execute ‘/etc/openhab2/scripts/ temperature’, but it is not contained in whitelist.
2020-07-01 14:47:12.406 [WARN ] [ng.exec.internal.handler.ExecHandler] - Tried to execute ‘/etc/openhab2/scripts/ humidity’, but it is not contained in whitelist.

Also nehme ich in die /etc/openhab2/misc/exec.whitelist folgende zwei Zeilen auf:
/etc/openhab2/scripts/ temperature
/etc/openhab2/scripts/ humidity

und der Fehler verschwindet

und habe nun noch in der event.log folgenden Fehler:
2020-07-01 17:31:43.973 [vent.ItemStateChangedEvent] - humidity_out changed from NULL to /usr/bin/env: ‘python3\r’: No such file or directory
/usr/bin/env: ‘python3\r’: No such file or directory

2020-07-01 17:31:43.975 [vent.ItemStateChangedEvent] - temperature_out changed from NULL to /usr/bin/env: ‘python3\r’: No such file or directory
/usr/bin/env: ‘python3\r’: No such file or directory

Weiß jemand, wie ich diesen wegbekommen?

Gruß Daniel

This form is English only.

The German forum is here.
German openHAB - KNX-User-Forum

1 Like

Try to use the path to python3 ( should be: /usr/bin/python3 ) instead of /usr/bin/env python3.

Versuch es mal mit dem Pfad zu python3 ( sollte dieser sein: /usr/bin/python3 ) an Stelle von /usr/bin/en python3.

1 Like

English please, and use code fences.

How to ask a good question / Help Us Help You - Tutorials & Examples - openHAB Community

1 Like

Hallo Wolfgang_S,

Thanks for your information.
But in my Configuration-Files (.sitemap, .script, …) I do not use /usr/bin/env python3 and I do not use /usr/bin/python3. Is there a Openhab or Python-Configuration File, where I can configure that?

In your first post you wrote

please try to change the first row in that file.

Hallo Wolfgang_S,
thank you very much. I changed that and now it works !!


I thought a line with a # at the Begining is a Comment and has no effect.
Why is it here importend?

A # alone would be a comment.
I Linux environment the first line starting with #! describes the shell or interpreter to be used to run the code inside of the file.

additional explanation:
this one starts the env command to execute python3.
Because the openhab user has a limited environment this does not run.

Hallo Wolfgang_S,

thank you very much for this information


Otherwise the programm might get executed as a java or bash file and would run into syntax errors. That’s the same as #!/bin/bash at the start of a shell script.
Most of the time it runs without as well however sometimes it might cause errors if you leave it out.