Another migration problem "Thinks and DHT22-Sensor"

That is what i was searching for. I am happy!
I will pay attention in future post more on my wording. I am very grateful to you for your perseverance and patience!

2 Likes

This is an old threat but exactly where I am currently facing some issues. I hope someone can help me. I am running openhabian an my RPI. Exec and Regex are installed, the DHT22 is connected to GPIO pin15. I am using wiringPi so, GPIO Port 3.

My DHT22 sensor is providing me values by executing the following simple script with

sudo /srv/openhab2-conf/scripts/dht22.sh 3 TEMP
#!/bin/bash
 
GPIO=$1
INPUT=$(/opt/lol_dht22/loldht $GPIO |grep "Temperatur")
HUM=$(echo $INPUT|cut -d " " -f3)
TEMP=$(echo $INPUT|cut -d " " -f7)
 
if [ "$2" = "HUM" ]; then
   echo $HUM
fi
 
if [ "$2" = "TEMP" ]; then
   echo $TEMP
fi

Let’s assume I receive the value 19.60.

Next I defined the exec thing to execute this command from openhab:

Thing exec:command:loldht22_tmp [
        command="/srv/openhab2-conf/scripts/dht22.sh 3 TEMP",
        transform="REGEX((.*?))", 
        interval=60,
        timeout=20,
        autorun=true]

My items looks like the following:

Number Klima_temp_wz "Temperatur [%.1f °C]" <temperature>
String Temp_wohnzimmer_out "Temperatur [%.1f °C]" <temperature> (temp_chart) { channel="exec:command:loldht22_tmp:output" }

to transform the string to number I used the rule from @rlkoshak, thank you therefore.

rule "Temp"
    when
        Item Temp_wohnzimmer_out received update
    then
        Klima_temp_wz.postUpdate(Temp_wohnzimmer_out.state.toString)
    Thread::sleep(5000)
    logInfo("temp", "Temperatur: " + Klima_temp_wz.state + "°C")
end 

sitemap is simple item integration

Text item=Klima_temp_wz icon=temperature

My problem is now, that I do not receive any values.

The log is providing the following line:

2018-11-05 12:26:06.801 [INFO ] [.eclipse.smarthome.model.script.temp] - Temperatur: NULL°C

And I got now a second issue message which seems like relating to the string:

2018-11-05 13:09:28.499 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert 'We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified' to a state type which item 'Klima_temp_wz' accepts: [DecimalType, QuantityType, UnDefType].

Does someone of you have an idea what went wrong or where I have a bug in my coding? I assume it is a coding thing because the manuell execution of the bash script is working proper.

Thank you in advance.

maybe? the openhab user is not a member of the sudoers

check: How to solve Exec binding problems

1 Like

Hi Angelos,

thank you for the quick reply.

Based on the linked discussion I added the following line:

openhab ALL=(ALL) NOPASSWD: /srv/openhab2-conf/scripts/dht22.sh, /opt/lol_dht22/loldht

to

sudo visudo -f /etc/sudoers.d/010_pi-nopasswd

Now I get a value.

Last question. Does this mean, every time, I like to use the exec command I should validate that the action I like to perform my openhab system has access rights?

Thank you so much, :slight_smile: You saved my vacation day :wink:

well… yes… :slight_smile: isn’t it normal?
by the way: you could have used NOPASSWD: ALL instead of listing the scripts in the sudoers file

That was @rlkoshak actually :slight_smile:

Yes for me as not the biggest Linux crack it was new to me:-). If I allow everything that could cause trouble or? With limited rights I assume to avoid problems if everything is accessible.

So thank to both of you :slight_smile:

well, the risk is not so big, so I wouldn’t worry too much about it and allow ALL
you are correct in your way of thinking but the probability of something going (horribly) wrong is too small.

Hi Angelos,

I added now the humidity and am getting the following issue message:

Cannot convert '' to a state type which item 'Klima_temp_wz' accepts: [DecimalType, QuantityType, UnDefType

For the humidity I am have another thing which calls the HUM of the script (and has a different name) and two new items that are part of a new rule. As well I am getting a value for Humidity.

But I don’t understand why the systems provides me this issue message (which is related to my temperature rule that worked without any problems) and what it means. Furthermore I had to add “sudo” at the beginning of the command, otherwise I don’t receive any values. I assume sth. in the rules is wrong? but I convert the string to number - so that the system should handle that or?

Kindly,
Woogi

Edit: Problem is gone. I just extended the refresh rate of the items from one to ten minutes. Maybe a restart or sth. like that fixed the problem…