First openHAB proj....almost there!?

I have been struggling with this since yesterday afternoon. Help appreciated.

I am using a Tiva Launchpad to send sensor status (binary - simple on or off of machine) to an RPi using 2 nrf24L01 radios, using mosquitto to bind to openHAB.

I have tested everything up to mosquitto and it works as it should (two terminal window test on pi, get status updates as I should)

Unfortunately, the openHAB portion of this project has me flummoxed. Upon trying to start openHAB, it seems to stick on "Loading Model ‘home.rules’. When I hit CTRL^C, it says “Stopped REST API Stopped Classic UI”

I’m having trouble understanding how things are linking up. I get some of it, but I’m still awash in multiple tutorials that all take a different approach. Any feedback is appreciated. Here are my pieces:

sitemap (taken from here):
Text label=“Laundry Room” icon=“firstfloor” {
Frame label=“Laundr Room Status”
{
Text item=itm_laun_washer_mqtt valuecolor=[<1=“gray”,==1=“green”,>1=“red”] labelcolor=[<1=“gray”,==1=“green”,>1=“red”]
}
}

items:
Group All

Group gGroundFloor

Group GF_Laundry "Laundry Room" <video> (gGroundFloor)

Number itm_laun_washer_mqtt "Washer [MAP(laundry.map):%s]" (ALL) {mqtt="<[mymisquitto:3042:state:default]"}

rules:
rule “Washer Complete”
when
Item itm_laun_washer_mqtt received update
then
if(itm_laun_washer_mqtt.state == 2)
{
say(“Washer Complete!”)
sendMail("oddlogic@gmail.com", “Washer is finished”, “Yay! Clean clothes!”)
}

end

I also meant to say that I have been following the homeautomationgeeks tutorial. I am fine with using what is stated there for a simple interface, but there seem to be parts missing. That or I don’t understand why we get outputs from the statements. I’m missing the pieces of how the device is actually being polled. I don’t get it!

With that said, I have followed everything else to the letter and have gotten positive results for all of my tests (mosquitto, etc) but have had no luck with openHAB. I know that my questions may not be very good yet, but maybe that’s the best place to start. What do you need from me to help troubleshoot my problem? Or what can I do to better direct myself?

Thanks!

You get a gold start from me for actually including THE most important pieces of information we need to help: your items and your rules.

Haven’t looked deeply at that site yet but have had it bookmarked for awhile. The polling might be done in a library somewhere. The fact that you are seeing MQTT messages (at least from the command line) indicates the polling is taking place.

It is probably not stuck so much as it has nothing to do after that point. Do you have other Items and bindings and rules in place that should cause additional activity to be sent to openhab.log?

A good place to look for activity is events.log. This is a log of everything that gets put on the event bus. So every update to every item will appear here. If your Item is configured correctly you will see it being updated in this log. If you don’t you know something is wrong with your item config.

Without getting deep into parsing your binding config which I can’t do right now (check the MQTT binding’s page) most everything looks reasonable except you might not have the topic there, unless the topic is “3042” which I think is unusual. usually topics are a bit more hierarchical and descriptive.

Here is a working MQTT input Item from my config for comparison.

Contact N_D_Front "Front Door [MAP(en.map):%s]" <frontdoor> (gDoorSensors, gRemindDoorSensors, gAlarmSensors, gHydraSensors)  { mqtt="<[mosquitto:entry_sensors/main/front_door:state:default]" }

You might need to change your check of the Item’s state to:

if((itm_laun_washer_mqtt.state as DecimalType) == 2)

but I think it should work as is.

Add some logging to your rules. logInfo("Name", "statement") where "Name" is handy to help you find the log statements, I usually use the rule name, and "statement" is something meaningful like "Washer Complete rule triggered with state = " + itm_laun_washer_mqtt.state

It is usually a good idea to have a logInfo as the first and the last line of your rule so you know if fully executed. It is also helpful to have one in each conditional so you can see the logic. Once debugging is done you can remove the statements or turn them into logDebug.

1 Like

Thanks for your help, Rich!

So in your statement, where do you define “entry_sensors/main
”, etc? Is it under the sitemap?

I will try debugging with log statements today. Thanks for the suggestion.

Brad

p.s.- you were right that 3405 was suspect. It should have been home/laundry/washer. This was the piece that I was missing! I think that I just looked at it for so long yesterday that it wasn’t clicking with me that mosquitto is reporting and we are picking it up with that statement in oH

update:

So I inserted some logging into the rules file, it now reads:

rule "Washer Complete"
	when
	Item itm_laun_washer_mqtt received update
	then
	if((itm_laun_washer_mqtt.state) == 1)
	{
	logInfo("washer", "washer is finished")
	say("Washer Complete!")
	sendMail("oddlogic@gmail.com", "Washer is finished", "Yay! Clean clothes!")
	}	
	if((itm_laun_washer_mqtt.state) == 0)
	logInfo("washer", "washer is not finished")
end

I went to my pi’s published site for openhab, and I get what I expect upon running openhab. I see mosquitto publishing the washer events that I have coming from my MCU, but the washer is not changing states, and I’m seeing no logging take place.

Where should we go from here?

That is my Item definition. The Sitemap never knows nor cares what an item is bound to. For that matter, neither do the rules. It is only in the Items files that you bind an Item to a binding.

First look in the events.log so see if openHAB is reading the events. Everytime there is an event itm_laun_washer_mqtt will have a line in events.log saying it was updated.

If you don’t see anything there then you know the problem is with the Item’s MQTT binding config in your items file.

If you do see statements then you need to add logging to debug the rule.

Like I said above, make the first and last line of the rule be a logging statement so you know it triggered and completed executing. Log out the state of itm_laun_Washer_mqtt to see if it is something unexpected (e.g. 01, or mapped to something else). If you rule is indeed triggering it means that itm_laun_washer_mqtt’s state is never 1 and never 0, but because you don’t have a logging statement at the top of your rule we never know if the rule ever triggers at all.

Update 2:

So I started oH in debug mode and I’ve noticed a few things that trouble me some -

  1. When I go to the openHAB.app page, the last paragraph has a line that says “Caused by: java.io.FileNotFoundException: configurations/transform/laundry.map” why is it looking for this?

  2. Near the top, while I am in debug mode, I see that - "loaded mqtt config fo item ‘itm_laun_washer_mqtt’ : 1 subscribers, 0 publishers - is that right? It seems like there should be a recognized publisher.

thanks for any help


-b

Because in your Items you have:

Number itm_laun_washer_mqtt “Washer [MAP(laundry.map):%s]” (ALL) {mqtt=“<[mymisquitto:3042:state:default]”}

That is telling openHAB that whenever you put itm_laun_washer_mqtt on your sitemap, and don’t override the label, to use laundry.map to get a human readable version of the state. Presumably laundry.map will have entries mapping the numerical states to a word.

The item is defined to only receive messages which makes it a subscriber. Nowhere in your rule do you send your own messages so unless you are doing something not posted, this is the correct behavior.

I don’t have a laundry.map file, so that’s a problem. :slight_smile:

When I get home, I’ll implement your debug suggestions. Thanks!

Yeah, it’s not binding. I checked the log files and they are completely blank. Can we go through how you might troubleshoot this if it were yours?

So I have this now for items:

Contact itm_laun_washer_mqtt “Washer [MAP(laundry.map):%s]” (ALL) {mqtt="<[mymosquitto:home/laundry/washer:state:default]"}

and I have this for rules:

rule "Washer Complete"
	logInfo("Washer", "Washer state at beginning of rules", itm_laun_washer_mqtt.state)
	when
	Item itm_laun_washer_mqtt received update
	then
	if((itm_laun_washer_mqtt.state) == 1)
	{
	logInfo("washer", "washer is finished")
	say("Washer Complete!")
	sendMail("oddlogic@gmail.com", "Washer is finished", "Yay! Clean clothes!")
	}	
	if((itm_laun_washer_mqtt.state) == 0)
	logInfo("washer", "washer is not finished")
	logInfo("Washer", "Washer state at end of rules", itm_laun_washer_mqtt.state)
end

the .cfg file:

mqtt:mymosquitto.url=tcp://192.168.137.53:1883
mqtt:mymosquitto.clientId=MyMQTT
mqtt:mymosquitto.qos=0
mqtt:mymosquitto.retain=true
mqtt:mymosquitto.async=true

and just for a sanity check, here is the mosquitto reporting taking place.

So I found a problem like mine on this site and decided that since I didn’t use apt-get (because I followed a tutorial that neglected to do so) that I would reinstall openHAB.

Now it starts as a service like it should, but I am no longer able to see the page pop up like I was before. Instead I’m getting error 500 with the home.sitemap could not be found.

So I looked at the /var/log/openhab/openhab.log file and see that I’m getting a warning that states that home.sitemap is either empty (it’s not) or cannot be parsed correctly. Hmm. Well, I think it looks just fine compared to other examples, but I have been playing around with it a bit, so here goes:

Text label="Laundry Room" icon=firstfloor"{
Frame label="Laundry Room Status"
{
	Text item=itm_laun_washer_mtqq
}
}

and with that, I’m going to bed. I’ve been at this all night.

cheers,

b-

Change this to your actual item:

Text item=itm_laun_washer_mqtt

In addition to that you are missing parenthesis in icon=firstfloor",
it should be icon="firstfloor"

Also, a COMPLETE sitemap which can be called by
<your_ip>:8080/openhab.app?sitemap=home
would look like this:

sitemap home label="Home"
{
Frame    {
        Text label="Laundry Room" icon="firstfloor"
                  {
                  Text item=itm_laun_washer_mqtt
                  }
         }
 }

I suggest using the OH Designer to avoid these syntax errors 


Do you mean that they didn’t have anything relevant in them about MQTT or that they were completely blank? If they are completely blank something else is wrong. When openHAB starts up it will add a page or more of log statements to openhab.log (lots of “Starting REST API” statements. Also, and importantly, you should see a statement saying the the MQT binding has started. Finally, you should see a line for each of your .items and .rules files being loaded. If there is an error parsing any of those it will appear there. Any errors with the files means nothing will work.

First lets simplify the Item definition to eliminate the number of variables. Get rid of the map and make it be a String so we can eliminate any parsing or casting problems.

String itm_laun_washer_mqtt "Washer [%s]" (ALL) {mqtt="<[mymosquitto:home/laundry/washer:state:default]"}

In my Item that I posted above, Contact works because my senders send the strings “OPEN” and “CLOSED” which the MQTT binding knows how to insert into a Contact. I’m not sure what it would do with a 1 or a 0 which is what it appears your publisher is sending.

I’m not certain the String will work either so if it doesn’t, switch it to a Number.

Personally, I would probably change my publisher to send something a little easier to deal with, like a text word (e.g “finished” instead of 1 and “running” instead of 0. It is easier to deal with text in openHAB than it is to deal with numbers.

When I said make a log statement as the first line of your rule, I ment in the then section. I don’t think putting a log statement before the when is valid. Also, lof info expects only 2 Strings so you need to concatenate using ‘+’, not a comma. Let’s cast the state to a DecimalType just in case that is causing a problem. Finally, lets apply proper indentation so it is more legible.

rule "Washer Complete"
when
    Item itm_laun_asher_mqtt received update
then
    logInfo("Washer", "Washer state at beginning of rules: " + itm_laun_washer_mqtt.state.toString)
    if((itm_laun_washer_mqtt.state as DecimalType) == 1) {
        logInfo("Washer", "Washer is finished")
        say("Washer Complete!")
        sendMail("oddlogic@gmail.com", "Washer is finished", "Tay! Clean clothes!")
    }
    else if((itm_laun_washer_mqtt.state as DecimalType) == 0) {
        logInfo("Washer", "Washer is not finished")
    }

    logInfo("Washer", "Washer rule completed")
end

As it was previously written I would not be surprised if openHAB rejected it as being invalid. You should have seen an error in openhab.log when it loaded the file if that is the case.

See @sihui 's post for help with the sitemap. I second his recommendation to use Designer. Its far better to catch syntax errors as you type then it is to debug them while it is running.

I think the openHAB 1.7x and earlier releases of the MQTT binding will send a DecimalType update to a String item when the incoming message can be parsed as a number, regardless of the kind of item it’s intended for, and which the String item won’t accept. But the PR I’ve submitted will send StringType updates to String items, DecimalType updates to Number items, PointType updates to Location items, etc., so there won’t be odd problems with how the message is parsed.

I figured that was the case. I just wasn’t sure what the old binding would do.

BTW, still trying to piece together a few minutes to try the new binding and see if the change broke anything. Will let you know when I do.

1 Like

I have implemented all changes suggested (thanks to you both). The sitemap now works and the page comes up as it should when visiting home.sitemap.

The binding is still not happening, I think. In openhab.log I see all of my changes to sitemap, items, and rules, but the status for the washer remains " - ".

Re: sending a string - I could do that but it seems unnecessary and since I’m working with C, it’s a bit cumbersome. I used the Number type with openHAB, then look at the number and compare in rules.

Re: openHAB Designer - for some reason the file menu does not provide any option for me but “exit.” When I try to modify a file and exit, it does attempt to save, but says that permission is denied. I don’t know why this is as I’ve given permissions to openhab in Samba, and am connecting to the network drive in the designer.

It’s a shame that this has been so rough. I can see that this is a powerful interface but sadly I don’t have the time for all of this. I have other projects, finals, reports, etc that I have to do. This is not a solution that lends itself to putting things together quickly, imo, and as such I’m forced to just use mqtt and python. All that is required of me is to get an email message from an event. I thought it would be nice to use the power of openHAB but this is all just too frustrating.

With that said, I will be back after the semester and look forward to putting in some more time in order to get my own projects off the ground. In fact, I still want to finish this one the way that I want to, so any help that you provided or will provide will not go to waste.

Again, I appreciate your time. I’ll see you in a few weeks.

Brad

The ’ - ’ means the Item is uninitialized so there is something wrong with the binding or the Item definition.

Lets step back to the beginning.

  1. Is the binding actually installed? You should have, among a bunch of other jar files, a file named org.openhab.binding.mqtt-1.7.1.jar in /usr/share/openhab/addons. When openhab starts up you should see a log statements along the lines of:

    2015-10-23 12:41:20.815 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
    2015-10-23 12:41:20.816 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection ‘mosquitto’

Only it should say that it is starting a connection to mymosquitto according to your item definition.

  1. When the items file is loaded do you see any errors? You should see something like:

    2015-10-23 12:41:30.579 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model ‘weather.items’
    2015-10-23 12:41:30.668 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model ‘garage.items’

But replace with the name of your items file.

  1. There is something wrong with the way the Item is configured. Try making it a String Item, like I said (see below) to eliminate strange problems with casting. Watch the openhab.log and events.log when the message is sent to see if an error is generated or if there is anything written when the MQTT message is sent to indicate what could be wrong.

ASCII is ASCII everywhere but an int can have multiple encodings based on what sort of byte ordering a given CPU or virtual machine prefers. Is that number encoded as Big Endian or Little Endian on the Arduino? How is an int encoded on the openHAB server? Is Mosquitto aware of the difference and transcode it for you or just pass it through? Does Java transcode it for you? Passing around raw numbers, especially between different types of machines can be a very tricky business.

You can avoid having to answer all of these questions if you just use ASCII, and since it doesn’t work


Even if you send ‘1’ and ‘0’ at least you will be sending ASCII and bypass all this ugliness. We can swap it to a Number once we can confirm that openHAB is able to read it.

For Designer you need to give permission to what ever user is running Designer to read and write to the files. I actually ended up just running Designer as root, but I’m running on the same machine as openHAB so that works. You probably need to check your samba permissions and make sure what ever user you are connecting to your server over samba has permission to write.

Beyond that, you can save individually changed files in Designer using <ctrl>-s. If I were to change one thing in Designer, it would be to add some of the expected menus in so doing simple things like loading the config directory and saving a file without closing it isn’t so opaque.

This is something I’ve said before and will continue to say to discouraged neophytes. Home Automation (HA) is HARD. It is complex and it takes many months of learning, experimenting, and banging your head against the wall to figure out. It is even harder if you don’t know programming and even then, if you have never been exposed to Enterprise Service Bus type programming or Actor Based programming openHAB can be a challenge. I’ve been a professional programmer for 20 years and it took me months to get to the point where I felt like I was competent. Anyone who comes to HA thinking they will be able to throw together a bunch of tutorials without understanding what they are doing inevitably hits a problem like this. Those who end up being successful are those who persist and push through the problem. I hope you do come back because ultimately, if you ever expand beyond some custom Arduino sensors you will need some sort of HA hub to tie everything together and IMHO openHAB is the best around.