Roi
(Martin)
March 19, 2021, 1:43pm
1
Hello,
I am a bit lost here trying to migrate my text based rules (in /etc/openhab/rules) into the GUI of openHAB 3.
What I use a lot are notifications through Telegram and XMPP.
Here are examples of the rules code I use until now:
XMPP:
val xmppAction = getActions("xmppclient","xmppclient:xmppBridge:xxx")
xmppAction.publishXMPP("user@xmppdomain.tld", new DateTimeType().format("%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS") + ": Test Message through XMPP")
Telegram:
val telegramAction = getActions("telegram","telegram:telegramBot:xxx")
telegramAction.sendTelegram(new DateTimeType().format("%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS") + ": Test Message through Telegram")
The ideal idea would be to create a helper script for each notification type which I can call with parameters (which e.g. contain the specific/different message for each notification). Is this possible, yet?
As I said, I lost track a bit. For sure I googled and looked here in the forum but did not find much which helps me. Maybe also because I am not very talented with programming.
Maybe someone can point me to the information I am looking for.
Thanks and cheers,
Roi
rlkoshak
(Rich Koshak)
March 19, 2021, 2:36pm
2
The first question is what is driving you to do this? There is no reason you need to abandon your .rules files unless there is some compelling reason. So make sure you are going though this extra work for some reason beyond “because I can.” It might be as simple as you want to be able to manage your Rules through MainUI.
This is not and probably never will be possible using Rules DSL. This is possible using JavaScript or Python. To see how to do it in JavaScript see OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules .
Roi
(Martin)
March 19, 2021, 3:06pm
3
The reason why I am working on this is because since upgrading to openHAB 3 it is “forgetting” my rules, sometimes, but it occurs several times per week. Sometimes (but very rare) it also forgot items. From what I was observing it only affects rules (and items) placed in the text files.
After restarting openHAB everything is fine again. And also when opening the text file(s), changing something and saving it. I can read in openlog.log that xxx.rules was loaded and the rules work again.
As I have many rules I can only guess how ofter this occurs as I do not notice a missing rule at once. Like alarm rules or stuff like this. What I can notice is if rollershutters to not open or close, the light does not go on in the cellar if there was motion detected. And so on.
With putting rules (and items) in the GUI I did not have any problems with these rules (and items) anymore.
That’s the reason.
Roi
(Martin)
March 19, 2021, 3:07pm
4
Thank you! I will take a look and hopefully understand it and use it for my goals.
rlkoshak
(Rich Koshak)
March 19, 2021, 3:07pm
5
Roi:
The reason why I am working on this is because since upgrading to openHAB 3 it is “forgetting” my rules, sometimes, but it occurs several times per week. Sometimes (but very rare) it also forgot items. From what I was observing it only affects rules (and items) placed in the text files.
Have you filed an issue or opened a discussion about that? It shouldn’t happen and is a bug.
Roi
(Martin)
March 19, 2021, 3:09pm
6
No, I did not, yet. The problem is that the error is there but I do not see anything else, e.g. in logs. Also no idea how to prove it, log it and so on.
rlkoshak
(Rich Koshak)
March 19, 2021, 3:17pm
7
Sometimes just knowing that the behavior occurs is enough to start an investigation. No one can guaranteed that it does get fixed. But it will never get fixed if you keep it to yourself.
rossko57
(Rossko57)
March 19, 2021, 4:23pm
8
OH3 is pickier about filenames. While in OH2 you got away with filenames like lights.outdoor.rules and lights.indoor.rules, in OH3 they will clash and editing one will mess up rules from the other.
Some people also seem to suffer from conflict problems with lights.rules and lights.items. That might be fixed now.
Roi
(Martin)
March 19, 2021, 8:47pm
9
You are right. I will open up a bug report about this.
rossko57:
OH3 is pickier about filenames. While in OH2 you got away with filenames like lights.outdoor.rules and lights.indoor.rules, in OH3 they will clash and editing one will mess up rules from the other.
Some people also seem to suffer from conflict problems with lights.rules and lights.items. That might be fixed now.
Thank you for this information. What does this mean exactly? My files are names like this:
shelly.items
shelly.rules
shelly.things
tasmota.items
tasmota.rules
tasmota.things
xiaomi.items
xiaomi.rules
My rule files can contain a lot of rules. Only some of the rule files have one or only a few rules.
rossko57
(Rossko57)
March 19, 2021, 9:31pm
10
Problematic in current openHAB stable release -
Rules are being removed on reload of Items.
Create one Item in test.items:
Switch Test_Switch “Test Switch”
And one Rule in test.rules:
rule “Switch Changed”
when
Item Test_Switch changed
then
logInfo(“”, “Test_Switch changed”)
end
Add a space to test.items and save.
Logs:
2021-01-21 21:05:55.140 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘test.items’
2021-01-21 21:07:10.739 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘test.rules’
2021-01-21 2…
Roi
(Martin)
March 20, 2021, 11:19am
11
Oh wow. So I need to wait for a fix or rename the files? What about:
items-xiaomi.items
rules-xiaomi.rules
Or is this also too extreme for the picky OH3? I would like to identify my files without any hassle.
rossko57
(Rossko57)
March 20, 2021, 11:27am
12
That would be fine. Every file ends up with a unique name, circumventing the bug.
Roi
(Martin)
March 20, 2021, 11:34am
13
Okay thank you. I will do that and restart OH3.
Btw, in my eyes a severe bug. Is it possible to push out a new stable version. It cannot stay that way. I mean, how would “normal” people “normally” name their files here?
rossko57
(Rossko57)
March 20, 2021, 11:52am
14
It’s not a severe bug at all. It’s a nasty gotcha for a few users, but circumvention is trivial.
So far as you and I can see, a fix has been developed and is already available in the development “milestone” versions, part of the normal development cycle.
If it’s that important to you, use the milestone release, accepting that you may be exposed to other changes.
Or if it’s not important, wait.
Roi
(Martin)
March 20, 2021, 1:21pm
15
You are right that it is not severe and also easy to circumvent. But the outcome is not too trivial and I would call it severe (if e.g. alarm rules do not work anymore and the user does not notice it). Also it is not that easy to get to it. See my case. It was only a coincidence. Personally I heard from two other people who have the same issue. Or might. Because sometimes after upgrading to OH3 some stuff was temporarily not working anymore. Looking back I think they have/had the same issue so I pointed them to this thread.
I am very happy that there are people like you and also @rlkoshak here to help users like me and also fixing stuff like this bug.
For now, I renamed my files and to be extra sure restarted OH3 after that.
About my question in the start post of this thread I will take it slowly and only touch rules and switch them to the GUI if I need to. Like when creating new rules or changing a lot of things for existing rules.
Thank you all again!
Max_G
(Max G)
April 2, 2021, 11:30pm
16
Seems a very logical thing to do… and I named my files like this too.
Whether this can be circumvented or not, it is a bug IMHO.
Imagine the outrage if opening a Word .doc would open a .pdf.
I am sure the reason for .rules. items was to clearly distinguish between them.
rossko57
(Rossko57)
April 3, 2021, 12:19am
17
Here is the issue, the bug, that was opened, dealt with, fixed, and closed with the fix incorporated in development versions.
opened 08:33PM - 28 Dec 20 UTC
closed 01:29PM - 06 Jan 21 UTC
I have issue similar to #1829 , but with different behavior:
My setup
* Setu… p completely made from files configuration (.rules and .things files)
* Version: Openhab 3.0.0, run in docker
* Full config in github: https://github.com/petrows/smarthome-openhab
Problems
* Reload of rules DSL file may remove all other rules from other files matching the pattern `name-XXX.rules`, e.g. reloading of `light.rules` file also removes rules from files `light-astrocolor.rules` and `light-sunrize.rules`
* Reload of items files with same name as rules files may remove rules from this file, e.g. reloading of `heating.items` removes all rules from `heating.rules`.
Examples how i can reproduce this:
Just after start, all rules are loaded (56 rules total):
```
openhab> openhab:automation listRules
----------------------------------------------------------------------------------------------------
ID UID NAME STATUS
----------------------------------------------------------------------------------------------------
1 common-1 System started IDLE
2 common-2 Presence master IDLE
3 common-3 Waterleak IDLE
4 common-4 Test devices responce time IDLE
5 common-5 Fridge start at friday IDLE
6 common-6 Fridge stop at sunday IDLE
7 gen-1 Marina Desktop light apply color on ON IDLE
8 gen-2 Treppe Up light apply color on ON IDLE
9 gen-3 Treppe Down light apply color on ON IDLE
10 gen-4 Petro Desktop light apply color on ON IDLE
11 heating-1 Heating safe switch IDLE
12 heating-2 Heating NIGHT IDLE
13 heating-3 Heating MORNING IDLE
14 heating-4 Heating DAY IDLE
15 heating-5 Heating EVENING IDLE
16 heating-6 Auto command IDLE
17 heating-7 Heating NS boost switch IDLE
18 heating-8 Heating presense switch IDLE
19 heating-9 Heating master switch IDLE
20 light-1 Ligth master mode IDLE
21 light-10 KG Lager light changed IDLE
22 light-2 Ligth master mode status IDLE
23 light-3 Light safe switch IDLE
24 light-4 KG safe switch IDLE
25 light-5 NS follow table power IDLE
26 light-6 BZ force both lights work together IDLE
27 light-7 Sunset Rule IDLE
28 light-8 Petro desktop power IDLE
29 light-9 KG Treppe light changed IDLE
30 light-astrocolor-1 Astrocolor: Reset lamps state IDLE
31 light-astrocolor-2 Astrocolor: Set lamps color according to daytime IDLE
32 light-sunrise-1 Sinrise emulation auto off IDLE
33 light-sunrise-2 Sinrise emulation start IDLE
34 motion-1 KG Motion detect treppe IDLE
35 motion-2 KG Motion detect Lager IDLE
36 notification-1 Online notify IDLE
37 notification-2 LowBattery notify IDLE
38 notification-3 Sunset Rule 2 IDLE
39 remote-1 Spiegel control SW IDLE
40 remote-2 House verlassen SW IDLE
41 remote-3 KG Ladder BOTTOM btn IDLE
42 remote-4 KG Ladder UP btn IDLE
43 remote-5 KG Lager btn IDLE
44 remote-6 Petro desktop remote IDLE
45 remote-7 Marina desktop remote IDLE
46 remote-8 SZ remote sw IDLE
47 remote-9 KU Arbeitlicht SW IDLE
48 washmachine-1 Washmachine power IDLE
49 yeelight-1 Yeelight 1 power IDLE
50 yeelight-2 Yeelight 1 brightness IDLE
51 yeelight-3 Yeelight 1 color temp IDLE
52 yeelight-4 Yeelight 1 color IDLE
53 yeelight-5 mi-lamp-2.pws power IDLE
54 yeelight-6 mi-lamp-2.pws brightness IDLE
55 yeelight-7 mi-lamp-2.pws color temp IDLE
56 zigbee-1 Coordinator log IDLE
----------------------------------------------------------------------------------------------------
```
In ~10 seconds 4 rules are removed (52 rules left). Removed:
- Astrocolor https://github.com/petrows/smarthome-openhab/tree/6a75f1eb21caacc7dfd98405fafe79a8e2d185fb/rules/light-astrocolor.rules
- Sunrize: https://github.com/petrows/smarthome-openhab/tree/6a75f1eb21caacc7dfd98405fafe79a8e2d185fb/rules/light-sunrise.rules
```
openhab> openhab:automation listRules
----------------------------------------------------------------------------------------------------
ID UID NAME STATUS
----------------------------------------------------------------------------------------------------
1 common-1 System started IDLE
2 common-2 Presence master IDLE
3 common-3 Waterleak IDLE
4 common-4 Test devices responce time IDLE
5 common-5 Fridge start at friday IDLE
6 common-6 Fridge stop at sunday IDLE
7 gen-1 Marina Desktop light apply color on ON IDLE
8 gen-2 Treppe Up light apply color on ON IDLE
9 gen-3 Treppe Down light apply color on ON IDLE
10 gen-4 Petro Desktop light apply color on ON IDLE
11 heating-1 Heating safe switch IDLE
12 heating-2 Heating NIGHT IDLE
13 heating-3 Heating MORNING IDLE
14 heating-4 Heating DAY IDLE
15 heating-5 Heating EVENING IDLE
16 heating-6 Auto command IDLE
17 heating-7 Heating NS boost switch IDLE
18 heating-8 Heating presense switch IDLE
19 heating-9 Heating master switch IDLE
20 light-1 Ligth master mode IDLE
21 light-10 KG Lager light changed IDLE
22 light-2 Ligth master mode status IDLE
23 light-3 Light safe switch IDLE
24 light-4 KG safe switch IDLE
25 light-5 NS follow table power IDLE
26 light-6 BZ force both lights work together IDLE
27 light-7 Sunset Rule IDLE
28 light-8 Petro desktop power IDLE
29 light-9 KG Treppe light changed IDLE
30 motion-1 KG Motion detect treppe IDLE
31 motion-2 KG Motion detect Lager IDLE
32 notification-1 Online notify IDLE
33 notification-2 LowBattery notify IDLE
34 notification-3 Sunset Rule 2 IDLE
35 remote-1 Spiegel control SW IDLE
36 remote-2 House verlassen SW IDLE
37 remote-3 KG Ladder BOTTOM btn IDLE
38 remote-4 KG Ladder UP btn IDLE
39 remote-5 KG Lager btn IDLE
40 remote-6 Petro desktop remote IDLE
41 remote-7 Marina desktop remote IDLE
42 remote-8 SZ remote sw IDLE
43 remote-9 KU Arbeitlicht SW IDLE
44 washmachine-1 Washmachine power IDLE
45 yeelight-1 Yeelight 1 power IDLE
46 yeelight-2 Yeelight 1 brightness IDLE
47 yeelight-3 Yeelight 1 color temp IDLE
48 yeelight-4 Yeelight 1 color IDLE
49 yeelight-5 mi-lamp-2.pws power IDLE
50 yeelight-6 mi-lamp-2.pws brightness IDLE
51 yeelight-7 mi-lamp-2.pws color temp IDLE
52 zigbee-1 Coordinator log IDLE
----------------------------------------------------------------------------------------------------
```
If i will update removed file "light-astrocolor.rules" with white space change:
```
[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'light-astrocolor.rules'
```
Rules return back to list (only from this file - nr 30 and 31):
```
openhab> openhab:automation listRules
----------------------------------------------------------------------------------------------------
ID UID NAME STATUS
----------------------------------------------------------------------------------------------------
1 common-1 System started IDLE
2 common-2 Presence master IDLE
3 common-3 Waterleak IDLE
4 common-4 Test devices responce time IDLE
5 common-5 Fridge start at friday IDLE
6 common-6 Fridge stop at sunday IDLE
7 gen-1 Marina Desktop light apply color on ON IDLE
8 gen-2 Treppe Up light apply color on ON IDLE
9 gen-3 Treppe Down light apply color on ON IDLE
10 gen-4 Petro Desktop light apply color on ON IDLE
11 heating-1 Heating safe switch IDLE
12 heating-2 Heating NIGHT IDLE
13 heating-3 Heating MORNING IDLE
14 heating-4 Heating DAY IDLE
15 heating-5 Heating EVENING IDLE
16 heating-6 Auto command IDLE
17 heating-7 Heating NS boost switch IDLE
18 heating-8 Heating presense switch IDLE
19 heating-9 Heating master switch IDLE
20 light-1 Ligth master mode IDLE
21 light-10 KG Lager light changed IDLE
22 light-2 Ligth master mode status IDLE
23 light-3 Light safe switch IDLE
24 light-4 KG safe switch IDLE
25 light-5 NS follow table power IDLE
26 light-6 BZ force both lights work together IDLE
27 light-7 Sunset Rule IDLE
28 light-8 Petro desktop power IDLE
29 light-9 KG Treppe light changed IDLE
30 light-astrocolor-1 Astrocolor: Reset lamps state IDLE
31 light-astrocolor-2 Astrocolor: Set lamps color according to daytime IDLE
32 motion-1 KG Motion detect treppe IDLE
33 motion-2 KG Motion detect Lager IDLE
34 notification-1 Online notify IDLE
35 notification-2 LowBattery notify IDLE
36 notification-3 Sunset Rule 2 IDLE
37 remote-1 Spiegel control SW IDLE
38 remote-2 House verlassen SW IDLE
39 remote-3 KG Ladder BOTTOM btn IDLE
40 remote-4 KG Ladder UP btn IDLE
41 remote-5 KG Lager btn IDLE
42 remote-6 Petro desktop remote IDLE
43 remote-7 Marina desktop remote IDLE
44 remote-8 SZ remote sw IDLE
45 remote-9 KU Arbeitlicht SW IDLE
46 washmachine-1 Washmachine power IDLE
47 yeelight-1 Yeelight 1 power IDLE
48 yeelight-2 Yeelight 1 brightness IDLE
49 yeelight-3 Yeelight 1 color temp IDLE
50 yeelight-4 Yeelight 1 color IDLE
51 yeelight-5 mi-lamp-2.pws power IDLE
52 yeelight-6 mi-lamp-2.pws brightness IDLE
53 yeelight-7 mi-lamp-2.pws color temp IDLE
54 zigbee-1 Coordinator log IDLE
----------------------------------------------------------------------------------------------------
```
And, they are functional (reacting on command `openhab:things trigger astro:sun:home:set#event START`) with proper log messages.
Here is the interesting part!
Updating of file `light` removes `light-astrocolor` again:
```
[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'light.rules'
openhab> openhab:automation listRules
----------------------------------------------------------------------------------------------------
ID UID NAME STATUS
----------------------------------------------------------------------------------------------------
1 common-1 System started IDLE
2 common-2 Presence master IDLE
3 common-3 Waterleak IDLE
4 common-4 Test devices responce time IDLE
5 common-5 Fridge start at friday IDLE
6 common-6 Fridge stop at sunday IDLE
7 gen-1 Marina Desktop light apply color on ON IDLE
8 gen-2 Treppe Up light apply color on ON IDLE
9 gen-3 Treppe Down light apply color on ON IDLE
10 gen-4 Petro Desktop light apply color on ON IDLE
11 heating-1 Heating safe switch IDLE
12 heating-2 Heating NIGHT IDLE
13 heating-3 Heating MORNING IDLE
14 heating-4 Heating DAY IDLE
15 heating-5 Heating EVENING IDLE
16 heating-6 Auto command IDLE
17 heating-7 Heating NS boost switch IDLE
18 heating-8 Heating presense switch IDLE
19 heating-9 Heating master switch IDLE
20 light-1 Ligth master mode IDLE
21 light-10 KG Lager light changed IDLE
22 light-2 Ligth master mode status IDLE
23 light-3 Light safe switch IDLE
24 light-4 KG safe switch IDLE
25 light-5 NS follow table power IDLE
26 light-6 BZ force both lights work together IDLE
27 light-7 Sunset Rule IDLE
28 light-8 Petro desktop power IDLE
29 light-9 KG Treppe light changed IDLE
30 motion-1 KG Motion detect treppe IDLE
31 motion-2 KG Motion detect Lager IDLE
32 notification-1 Online notify IDLE
33 notification-2 LowBattery notify IDLE
34 notification-3 Sunset Rule 2 IDLE
35 remote-1 Spiegel control SW IDLE
36 remote-2 House verlassen SW IDLE
37 remote-3 KG Ladder BOTTOM btn IDLE
38 remote-4 KG Ladder UP btn IDLE
39 remote-5 KG Lager btn IDLE
40 remote-6 Petro desktop remote IDLE
41 remote-7 Marina desktop remote IDLE
42 remote-8 SZ remote sw IDLE
43 remote-9 KU Arbeitlicht SW IDLE
44 washmachine-1 Washmachine power IDLE
45 yeelight-1 Yeelight 1 power IDLE
46 yeelight-2 Yeelight 1 brightness IDLE
47 yeelight-3 Yeelight 1 color temp IDLE
48 yeelight-4 Yeelight 1 color IDLE
49 yeelight-5 mi-lamp-2.pws power IDLE
50 yeelight-6 mi-lamp-2.pws brightness IDLE
51 yeelight-7 mi-lamp-2.pws color temp IDLE
52 zigbee-1 Coordinator log IDLE
----------------------------------------------------------------------------------------------------
```
Rules from `light-astrocolor` disappears again. Also, they are not reacting on trigger anymore.
Please, let me know, if i can help you with some logs or something.
What else did you want to happen?