Another migration problem "Thinks and DHT22-Sensor"

sensor
openhab2
things
Tags: #<Tag:0x00007f1e68473050> #<Tag:0x00007f1e68472678> #<Tag:0x00007f1e684719d0>
(Rich Koshak) #9

You don’t. I was showing you the part of your rule that is wrong.

I’ll say it once again, DEFINE YOUR ITEMS AS NUMBERS

Number TEMP_Keller4 "Temp 4 Keller [%s]" 	<temperature> (gTemp) {channel="exec:command:dht22temp4:output"}
Number LUFT_Keller4 "Luftf. 4 Keller [%s]"	<temperature> (gTemp) {channel="exec:command:dht22hum4:output"}
0 Likes

(Test) #10

Sorry now I understand :slight_smile: But I have treied that already. It is not working.

2017-06-27 19:41:47.528 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type REGEX
2017-06-27 19:41:47.531 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable
0 Likes

(Rich Koshak) #11

“Cannot get service reference for transformation service of type REGEX”

Probably means you don’t have the REGEX addon installed.

0 Likes

(Test) #12

Thank you for this further note. But this only fixes another problem. I still get no values when I change the item to “number”.

0 Likes

(Rich Koshak) #13

I’m sorry if I come off a little angry, but I’m becoming frustraited with this and a couple of other threads where I have to play 20 questions for every new reply and half of my replies and links are not being read.

At this point I have no idea what you have done, what you have working and what is not working. I’m through trying to figure problems out with only “its broken” to go on.

Here is how I would do it. If it doesn’t work post here (and for any new problem you have) at a minimum:

  • relevant Things
  • relevant Items
  • relevant Rules
  • relevant sitemap entries
  • relevant logs, especially if there are errors
#!/bin/bash

INPUT22=$(/home/openhabian/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 22)
TEMP22=$(echo $INPUT22|cut -d " " -f1 | sed 's/[^0-9.]*//g')
HUM22=$(echo $INPUT22|cut -d " " -f2 | sed 's/[^0-9.]*//g')

INPUT4=$(/home/openhabian/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 4)
TEMP4=$(echo $INPUT4|cut -d " " -f1 | sed 's/[^0-9.]*//g')
HUM4=$(echo $INPUT4|cut -d " " -f2 | sed 's/[^0-9.]*//g')
ADDW=5.00

if [ "$1" = "HUM22" ]; then
echo $HUM22 $ADDW | awk '{print $1 + $2}'
fi

if [ "$1" = "TEMP22" ]; then
echo $TEMP22
fi

if [ "$1" = "HUM4" ]; then
echo $HUM4 $ADDW | awk '{print $1 + $2}'
fi

if [ "$1" = "TEMP4" ]; then
echo $TEMP4
fi

I’m assuming that this string returns a parsable number with no stray characters and no leading or trailing white space.

Things:

exec:command:dht22temp4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh TEMP4", interval=120, timeout=10]
exec:command:dht22hum4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh HUM4", interval=110, timeout=10]

Items:

Number TEMP_Keller4 "Temp 4 Keller [%.1f]" 	<temperature> (gTemp) {channel="exec:command:dht22temp4:output"}
Number LUFT_Keller4 "Luftf. 4 Keller [%.1f]"	<temperature> (gTemp) {channel="exec:command:dht22hum4:output"}

Rule:

rule "test123"
when
    Item TEMP_Keller4 received update
then
    logInfo("Test", "Bla: " + TEMP_Keller4.state.toString)

    var tempPlusFive = (TEMP_Keller4.state as Number) + 5

    logInfo("Test", "Plus 5: + tempPlusFive)
end

Sitemap:

Text item=TEMP_Keller4

If for some reason the script is not returning a value that can be parsed into a String (e.g. contains white space) see this posting for how to trim out the whitespace using a JavaScript transform.

1 Like

(Test) #14

Again thank you so much for your help and sorry for making you frustraited.

But as I told you before. It is not possible to change the item to a “Number”:

I have copied everything from you to be sure:

exec:command:dht22temp4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh TEMP4", interval=20, timeout=10 ]
exec:command:dht22hum4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh HUM4", interval=120, timeout=10 ]

items

Number TEMP_Keller4 "Temp 4 Keller [%.1f]" 	<temperature> (gTemp) {channel="exec:command:dht22temp4:output"}
String TEMP_Keller4_string "Temp 4 Keller String [%s °C]" 	<temperature> (gTemp) {channel="exec:command:dht22temp4:output"}
Number LUFT_Keller4 "Luftf. 4 Keller [%.1f]"	<temperature> (gTemp) {channel="exec:command:dht22hum4:output"}

sitemap

Text item=TEMP_Keller4
Text item=TEMP_Keller4_string

Result:

0 Likes

(George Erhan) #15

Are you for real???
I am hoping you are not!
Sorry for the possible frustration I may cause!
openHAB is for the ones that understand the basics of logic, the rest are details (sorry to be rude again!)

Best regards,
George

0 Likes

(Test) #16

@george.erhan: Your post is not very helpful. Could you please explain me your frustation?

0 Likes

(George Erhan) #17

OK!!!

So, you thought you had a problem:

Then @rlkoshak said:[quote=“rlkoshak, post:2, topic:30449, full:true”]
the proper word is “Thing”, not “Think”.

Your TEMP_Keller4 Item has an incomplete Channel ID. I think it needs to end in “:output” like your Luftf one does.

Change the permissions on /var/lib/openhab2/.python-eggs to remove write permissions from group and others
sudo chmod go-w /var/lib/openhab2/.python-eggs

I don’t know if I fully understand the question. But if you are asking for a way to have “TEMP4” to be passed to the script as a command line argument you need to create a String Item linked to the input channel. Whatever that String Item is set to gets appended to the command as a command line argument.

If you want the string “TEMP4” to be part of the value that TEMP_Keller4 receives you need to have your script echo that as part of its output.

channel="exec:command:dht22:TEMP54 is not a valid channel ID and is meaningless in OH.
[/quote]

Then you said:[quote=“Quake3Arena, post:3, topic:30449”]
Thank you so much!

It is working:

Items:

String TEMP_Keller4 “Temp 4 Keller [%s]” <temperature> (gTemp) {channel=“exec:command:dht22temp4:output”}
String LUFT_Keller4 “Luftf. 4 Keller [%s]” <temperature> (gTemp) {channel=“exec:command:dht22hum4:output”}

Things:

exec:command:dht22temp4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh TEMP4", interval=120, timeout=10]
exec:command:dht22hum4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh HUM4", interval=110, timeout=10]

But how can i convert a string to a number to use it in my old OH1 rules (to calculate the ventilation).

OLD Item (what i am using in rules):

Number LUFT_Keller4 “Luftf. 4 Keller [%.1f %%]” <temperature> (gTemp) { exec="<[/srv/openhab2
[/quote]

Then Rich said:[quote=“rlkoshak, post:4, topic:30449, full:true”]
If the only thing the script returns of a valid number with no white space around it, just change your String Item to a Number Item. Otherwise you need a transform or rule to convert it to something that can be parsed into a number.
[/quote]

Then you said:[quote=“Quake3Arena, post:5, topic:30449”]
I am to stupid :wink:

rule "test123"
when
Time cron "0/10 * * * * ?"
then
var Number vtemp_keller4 = (TEMP_Keller4.state as DecimalType).intValue
logInfo(“Test”, "Bla: " + TEMP_Keller4.state + " Blub: " + vtemp_keller4)

end

2017-06-27 17:28:40.009 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule test123: org.eclipse.smarthome.core.library.types.DecimalType
2017-06-27 17:28:50.009 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule test123: org.eclipse.smarthome.core.library.types.DecimalType
2017-06-27 17:29:00.014 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule test123: org.ecli
[/quote]

And then you said:[quote=“Quake3Arena, post:6, topic:30449, full:true”]
I have a workaround but without the decimal places:

rule “UpdateToNumber"
when
Item TEMP_Keller4_string received update or
Item LUFT_Keller4_string received update
then
var Number Temp
var Number Luft
Temp=Integer::parseInt(String::format(”%s",TEMP_Keller4_string.state).substring(0,2))
TEMP_Keller4.postUpdate(Temp)
Luft=Integer::parseInt(String::format("%s",LUFT_Keller4_string.state).substring(0,2))
LUFT_Keller4.postUpdate(Luft)

logInfo("Test", "Bla-: " + TEMP_Keller4 + " Blub-: " + LUFT_Keller4)

end

Bla-: TEMP_Keller4 (Type=NumberItem, State=21, Label=Temperature, Category=null) Blub-: LUFT_Keller4 (Type=NumberItem, State=70, Label=Luftfeuchtigkeit, Category=null)

But if I do

substring(0,4)

as needed, I will get an error:

2017-06-27 18:51:00.451 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘UpdateToNumber’: For input string: “21.5”

Thats bad because I want to have the 21.7 as an exaple.
[/quote]

And then Rich said:[quote=“rlkoshak, post:7, topic:30449, full:true”]
You cannot just cast a String into a DecimalType. You must parse the String.

(TEMP_Keller4.state as DecimalType)

for a String Item is nonsensical. You must parse the String into a Number.

Like I said:

If the only thing the script returns of a valid number with no white space around it, just change your String Item to a Number Item.
[/quote]

And in your almighty wisdom, you asked:[quote=“Quake3Arena, post:8, topic:30449”]

Sorry but where in my test rule i have to enter it?
[/quote]

And Rich patiently answered:[quote=“rlkoshak, post:9, topic:30449”]
You don’t. I was showing you the part of your rule that is wrong.

I’ll say it once again, DEFINE YOUR ITEMS AS NUMBERS

Number TEMP_Keller4 “Temp 4 Keller [%s]” <temperature> (gTemp) {channel=“exec:command:dht22temp4:output”}
Number LUFT_Keller4 “Luftf. 4 Keller [%s]” <temperature> (gTemp) {channel=“exec:command:dht22hum4:output”}
[/quote]

And then you come back:[quote=“Quake3Arena, post:10, topic:30449”]
Sorry now I understand :slight_smile: But I have treied that already. It is not working.

2017-06-27 19:41:47.528 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type REGEX
2017-06-27 19:41:47.531 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn’t transform response
[/quote]

And Rich tries to keep his calm down:[quote=“rlkoshak, post:11, topic:30449, full:true”]
“Cannot get service reference for transformation service of type REGEX”

Probably means you don’t have the REGEX addon installed.
[/quote]

And then you finally try to not be proactive:[quote=“Quake3Arena, post:12, topic:30449, full:true”]
Thank you for this further note. But this only fixes another problem. I still get no values when I change the item to “number”.
[/quote]

And RIch as calm as he trie to be, loses his temper (absolutely justifiable in your case):[quote=“rlkoshak, post:13, topic:30449, full:true”]
I’m sorry if I come off a little angry, but I’m becoming frustraited with this and a couple of other threads where I have to play 20 questions for every new reply and half of my replies and links are not being read.

At this point I have no idea what you have done, what you have working and what is not working. I’m through trying to figure problems out with only “its broken” to go on.

Here is how I would do it. If it doesn’t work post here (and for any new problem you have) at a minimum:

relevant Things
relevant Items
relevant Rules
relevant sitemap entries
relevant logs, especially if there are errors

#!/bin/bash

INPUT22=$(/home/openhabian/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 22)
TEMP22=$(echo $INPUT22|cut -d " " -f1 | sed ‘s/[^0-9.]//g’)
HUM22=$(echo $INPUT22|cut -d " " -f2 | sed 's/[^0-9.]
//g’)

INPUT4=$(/home/openhabian/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 4)
TEMP4=$(echo $INPUT4|cut -d " " -f1 | sed ‘s/[^0-9.]//g’)
HUM4=$(echo $INPUT4|cut -d " " -f2 | sed 's/[^0-9.]
//g’)
ADDW=5.00

if [ “$1” = “HUM22” ]; then
echo $HUM22 $ADDW | awk '{print $1 + $2}'
fi

if [ “$1” = “TEMP22” ]; then
echo $TEMP22
fi

if [ “$1” = “HUM4” ]; then
echo $HUM4 $ADDW | awk '{print $1 + $2}'
fi

if [ “$1” = “TEMP4” ]; then
echo $TEMP4
fi

I’m assuming that this string returns a parsable number with no stray characters and no leading or trailing white space.

Things:

exec:command:dht22temp4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh TEMP4", interval=120, timeout=10]
exec:command:dht22hum4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh HUM4", interval=110, timeout=10]

Items:

Number TEMP_Keller4 “Temp 4 Keller [%.1f]” <temperature> (gTemp) {channel=“exec:command:dht22temp4:output”}
Number LUFT_Keller4 “Luftf. 4 Keller [%.1f]” <temperature> (gTemp) {channel=“exec:command:dht22hum4:output”}

Rule:

rule "test123"
when
Item TEMP_Keller4 received update
then
logInfo(“Test”, "Bla: " + TEMP_Keller4.state.toString)

var tempPlusFive = (TEMP_Keller4.state as Number) + 5

logInfo("Test", "Plus 5: + tempPlusFive)

end

Sitemap:

Text item=TEMP_Keller4

If for some reason the script is not returning a value that can be parsed into a String (e.g. contains white space) see this posting for how to trim out the whitespace using a JavaScript transform.
[/quote]

And then you try again:[quote=“Quake3Arena, post:14, topic:30449, full:true”]
Again thank you so much for your help and sorry for making you frustraited.

But as I told you before. It is not possible to change the item to a “Number”:

I have copied everything from you to be sure:

exec:command:dht22temp4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh TEMP4", interval=20, timeout=10 ]
exec:command:dht22hum4 [command="/srv/openhab2-conf/scripts/AM2302sensor.sh HUM4", interval=120, timeout=10 ]

items

Number TEMP_Keller4 “Temp 4 Keller [%.1f]” <temperature> (gTemp) {channel=“exec:command:dht22temp4:output”}
String TEMP_Keller4_string “Temp 4 Keller String [%s °C]” <temperature> (gTemp) {channel=“exec:command:dht22temp4:output”}
Number LUFT_Keller4 “Luftf. 4 Keller [%.1f]” <temperature> (gTemp) {channel=“exec:command:dht22hum4:output”}

sitemap

Text item=TEMP_Keller4
Text item=TEMP_Keller4_string

Result:
[/quote]

Does all this fully detailed story explain the frustration?

Thanks in advance,
George

0 Likes

(Test) #18

Ok, in retrospect, some of my posts might be overpowered and I should have thought about it. Nevertheless, I try to understand the core statement: “Change the item from String to Number” and exactly that does not work.
Or is my English so bad that I understand everything here completely wrong?
I apologize seriously that I can not see my mistake here.

0 Likes

(Test) #19

btw.:

Is that “only a number” or do you mean that the dot is not valid for the number-item? If that is the case I realy understand your frustation and my fail…

0 Likes

(Rich Koshak) #20

This is false. You have provided absolutely no information to indicate that it is impossible to use a Number Item. All you have said is “it doesn’t work” with no details. You post no logs with errors. You have yet to post exactly what it is your script actually returns (i.e. does it include spaces around the number? does it include units or something else like that)?

Are there any errors in the log?

In this posting and your later posting it is clear that the number should be parsable so, lets just assume that a Number cannot work with the output channel of the Exec 2.x binding.

In that case you have two options. Create another Number Item that gets updated every time the TEMP_Keller4_String Item gets updated:

rule "Convert String temp to Number"
when
    Item TEMP_Keller4_String received update
then
    TEMP_Keller4.postUpdate(TEMP_Keller4_String.state.toString)
end

or convert the String to a number wherever you want to use it in a rule:

rule "Some rule that does math on TEMP_Keller4"
when
    Some trigger
then
    // do some rule stuff

    val tempVal = Float::parseFloat(TEMP_Keller4.state.toString)

    val plusFive = tempVal + 5

    // do other stuff
end

The source of my frustration is you do not provide enough details to really help you. I either have to drag details out of you by asking lots and lots of questions that should have been included as part of your posts or make wild guesses as to what you are trying to accomplish. Both take a lot of time and cause a lot of frustraition.

Instead of " I still get no values when I change the item to “number”." which could mean anything from your script is outputing something that cannot be parsed into a number to you messed something up, you could say:

"I tried to change the Item to a Number:

Number TEMP_Keller4 "Temp 4 Keller [%.1f]" 	<temperature> (gTemp) {channel="exec:command:dht22temp4:output"}

The sitemap still shows “-”.

I see these errors in the logs:

// logs showing errors

I changed the rule to be this:

// new rule with changes

when I run the script it returns this

// screenshot like you finally did
"

To have any hope of helping we need all of this information almost every step of the way. Otherwise it is like going to the doctor and saying “I hurt” and making him ask a million questions just to figure out where it hurts. Help us help you by providing as many details and help you can.

1 Like

(Test) #21

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

(Martin) #22

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.

0 Likes

(Angelos) #23

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

check: How to solve Exec binding problems

1 Like

(Martin) #24

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:

0 Likes

(Angelos) #25

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:

0 Likes

(Martin) #26

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:

0 Likes

(Angelos) #27

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.

0 Likes

(Martin) #28

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…

0 Likes