Do you have any lambdas defined in that .rules file? This includes createTimer, forEach, etc.
Nope, don’t believe so.
PS I did figure out why I couldn’t control my gateway, so manage to fix it and the sensors connected to it! I’ll post a solution in the Mi home binding thread where others also had the issue.
So, I found what is giving me that “Scheduled runnable ended with an exception” error. It appears to be when I try to convert the astro binding Sunrise time to DateTimeType.
DateTime Sunset_Time "Sunset [%1$tH:%1$tM]" { channel="astro:sun:local:set#start" }
If I set a variable to the state, it works.
However, if I do this:
var test = Sunset_Time.state as DateTimeType
I get the error:
[WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception
java.lang.NullPointerException: null
at org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl.lambda$1(RuleEngineImpl.java:315) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at ava.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
at java.lang.Thread.run(Thread.java:745) [?:?]
And I have no idea why.
Is that variable a global? I’m going to guess it is.
It might be the case that your Rule is running before the Astro binding has a chance to populate Sunset_Time. That means that Sunset_Time is NULL and NULL is not an instance of DateTimeType which is causing an exception to be thrown when the Rules engine tries to populate the global variables.
I suggest initializing test to null and then create a rule that triggers when Sunset_Time changes to set the state to test. Then add a check in your Rules that use test to check whether test is null before trying to use it.
var DateTimeType test = null
rule "Sunset time changed"
when
Item Sunset_Time changed
then
test = Sunset_Time.state as DateTimeType
end
Of course, this all begs the question, why don’t just use Sunset_Time.state in your rules that use test in the first place?
Well, it was rather just an example I used in my rules file to test the error’s occurance. I actually have this code on startup to determine whether my system should be in day or night ‘mode’ (which affects automatic lights, etc).
I apologise if it is a bit clunky, its not the cleanest solution most likely.
logInfo("System","Doing Astro check...")
var sunSet = new DateTime((Sunset_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli) - 600000
var sunRise = new DateTime((Sunrise_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli) + 600000
logInfo("System","Checking times: Sunset: " + sunSet + ", Sunrise: " + sunRise + " - Now: " + now)
if (now > sunRise && now < sunSet) DayMode = true
Both sunSet and sunRise are local to the Startup rule. I see the first log, then the error appears.
What I’m wondering about the most is that this code worked fine before my system started giving me errors (which happened after I uninstalled and reinstalled the Xiaomi Mi Home binding).
So I don’t know if its is a more core system that has perhaps become corrupted.
The only other notable change was upgrading to the lastest OH version, which I did in an attempt to resolve my previous issue where OpenHAB didn’t even want to start.
I think I broke my system. :<
Edit: (Not really, I thought of it before I submitted my reply…)
I suppose I could maybe rather do that check using this in a single line rather than 3.
if (now > Sunrise_Time.state && now < Sunset_Time.state) DayMode = true
I don’t think now supports < or >. You have to use the isAfter methods as demonstrated in Design Pattern: Time Of Day.
But your error is happening before that line.
I still think that it isn’t worked before because if a trick of timing and it is failing here because one of the Astro items had not yet been populated by the astro binding.
Check to see if this test items are NULL and log out of they are.
You can mitigate this by using restoreOnStartup on these Items or by triggering the role that checks on when either of those items receive an update.
Okay, awesome, thanks for the suggestions. I’ll take a look at that Astro binding timings as well as the time comparison functions.
Thank you very much @rlkoshak.
I decided to scrap my way entirely, and use method you illustrate in the link you provided.
I also then applied the rest of my changes that occurs in day or night times by checking for an update to a “Time” string.
It works 100%, and is in fact better than before. I still don’t really know what the error was, but doing it this way around doesn’t actually throw the error, so it seems very likely that timing might have been an issue. I put somewhat of a delay before loading the astro data, and haven’t seen the error since.
I tested with no delay, but even with that it still worked. I can’t seem to recreate the error now lol.
So an update!
Since the previous issues, I reinstalled my entire openHAB setup, and it works much better now.
The Astro binding works flawlessly so I think my SD Card might have been corrupted.
I have also now installed Motion on my Pi to record and act as a server for my IP cameras.
This works pretty well, and also allows me to stream the camera directly in Basic UI, even through cloud, so I don’t need to open up my home network to WAN anymore, which is great.
I have found that after a few days, the RAM on the Pi gets used up, and openHAB starts to fail with memory exceeded errors, forcing me to restart the Pi.
I think the culprit might be motion, so I am planning on buying another Rasberry Pi (3rd gen I think) and put openHAB on that, and run Motion on its own on my old Pi.
UI wise, I’m still contemplating using HabPanel. I see many people on here use it to great extend, with nice UI designs.
I might eventually create a habpanel for a control tablet, and then use Basic UI for my phones, etc.
Cool Stuff
Few cool things I am doing with my Basic UI (not very impressive, but cool nonetheless).
- I added a bunch of custom icons, and also implemented using the Weather Underground weather conditions icons to update on Basic UI. Works great for the most part.
- I change the Temp icon depending on whether it is hot or cold. Also works great.
- I use the visibility attribute to show certain important information at the top of the Basic UI menu when applicable, for example, if humidity goes over 95%, or the wind speed is very high, it will display it in the front UI.
- I also use this for displaying when my gate or garage is open.
Alarm
Another thing I’m working on now is an alarm. I can arm the alarm using switches, and also have it trigger and play the “Alarm Sound” on my Xiaomi Gateways. Unfortunately, at the moment the ability to upload custom sound effects to the Gateways appears to be disabled. So I can’t upload a proper alarm sound effect, which is somewhat annoying.
I also tried to implement a Alarm Code entry using a bunch of switches that update a String field, and use this to disarm the alarm.
But there is a slight delay using this method, (because it has to update the state of each ‘line’ of numbers) so to quickly and accurately type in the code is somewhat hard.
This, and the fact that I cannot upload an alarm sound right now to the Gateway, has paused this part of my project for now.
Sonoff MQTTT
I bought a Sonoff Basic, (preflashed with Tasmota firmware) and tried to get it to work with openHAB, and I’m still struggling.
I installed a MQTTT server on the Pi, and openHAB can connect to the broker. That part seems to work.
But getting the Sonoff to respond to commands or report its status is still not working, despite following several guides.
I’ll tackle it again later this week, maybe start over. I think my understanding of MQTT(T?) isn’t comprehensive enough yet, so I’ll read up on that first.
Next Up
- Add a switch/smart doorbell at the gate, that will notify openHAB, ring the bell on the Gateways (for now, later a notification to Google Home would be awesome), and take a picture from the camera at the gate, sending it as a notification to my phone.
- Complete my alarm system with my current sensors
- See if I can use a special HTTP ‘server’ addon for my existing alarm system in my home (an IDS) to interface with my PI, and then in effect with my openHAB setup. If I can integrate the two, I’ll have a very versitle smart alarm system.
- Replace the rest of the lights in my house with smart bulbs
- If I can get the Sonoff MQTTT stuff working, I want to replace the non-bulb lights in my house to work with Sonoff relays. I’ll also add other stuff eventually, like on fans, because I can actually buy these Sonoff relays locally, which is great for my wallet.
UI Screenshots
Hi,
That looks really great,
One quick question, how did you arm the alarm via openhab?
Cheers,
Pim
I have to mention when I say alarm, I just mean an internal alarm using openHAB (using various sensors I have everywhere). So I don’t actually currently have a connection to an existing external alarm, still working on that one.
So this arming is simply a mapped Number item with 4 states (Off, Home, Guest, Away), with sensors triggering an alarm state depending on the Alarm value.
Hi Sky.
I am from the sunny mp.
did you come right with the flashing of your Sonnoffs
I use the son off t1 switches. and run a LDR Outside connected to a esp8266 to monitor my light outside. in this side of the world we have to create most of our sensors and stuff our selfs.
Well, I bought them pre-flashed, because I didn’t have the right parts to flash it myself. But as I understand it, the flashing part isn’t too troublesome.
However, I’m still having trouble getting the sonoff basic to work correctly with my system.
For some reason after initial setup worked, it eventually starts doing weird things like consistently turning itself off.
I would turn on the switch via openHAB, and a few minutes later, it just turns off, with no report or anything. So still trying to figure that out.
Tasmota itself is great though, very easy to set up and connect to the MQTT server. Just need to figure out why its not working.
I had same isues. And came down to rules and also using espurna that alowes on device rules that i mised around with. And removed that and now it works
Are you using Espurna now as your firmware on it?
yes on my sonoff T1 us/au switches .
the others at the stage did not function correctly on the. but I am happy with espurna on them.
Ah okay.
I’m thinking I need to get one of those cables for the flashing, and try reflashing my sonoffs manually, and see if that helps me fix the issues I’m having on mine. Cause I have two more, so if the one works well, I can use the other two for other cool stuff.
I bought one of these.
I use myne alot. Still looking for pogo pins. Will recommend you get one. then you can test the different custom firmware that there is. and not be dependent from other means to get the firmware on to the units. and if you run in to problems with the units you can do your own fault finding and setup as well . I am glad that I am not the only South African using openhab and is active on the forums.
Awesome, thanks for the link, will check it out.
Its great I’ve found another South African doing some automation. Always helps when there is local people if I need any local tools or items.
I’ll post an update on my current automation stuff soon. Had to stop buying new stuff for a bit, cause of how much import costs are at the moment. (And my financial situation. =P)
some thing to look at there prising is not bad.