Virtual Items ans rules

Hi there,

This is my first try with OH rules. For testing purpose, I created a new instance of an OH docker container, running V2.4.0-snapshot-debian, build 1378.

In OH I created four switches SW1 to SW4 as “virtual items” without any connected channels.

Switch SW1 "SW1" <motion>
Switch SW2 "SW2" <motion>
Switch SW3 "SW3" <motion>
Switch SW4 "SW4" <motion>

For having access to the items (PaperUI seems not to show items without channels in the control-section?) there is a simple sitemap:

sitemap myhometest label="Test" {
	Frame label="Sitemap1" {
		Switch item=SW1 icon="receiver"
		Switch item=SW2 icon="screen"
	}
	Frame label="Sitemap2" {
		Switch item=SW3 icon="cinema"
		Switch item=SW4 icon="cinema"
	}
}

Via rules I simply try to switch SW3 when SW1 changes from off to on.

rule "test"
when
	Item SW1 changed from OFF to ON
then
	logWarn("Testlog", "Rule fired")
	SW3.sendCommand(ON)
end

But nothing happens when SW1 is klicked in the sitemap. Logs say, that the rules were loaded correctly. What seems strange is, that there are absolutely no entries in the events.log. Which might explain why the rule is not working…but why does klicking on the switch does not trigger events? Or am I missing here something else?

2018-10-03 12:55:04.034 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript
2018-10-03 12:55:05.489 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2018-10-03 12:55:05.534 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-10-03 12:55:06.267 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://172.17.0.4:6444
2018-10-03 12:55:06.269 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://172.17.0.4:6443
2018-10-03 12:55:11.497 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'myitemstest.items'
2018-10-03 12:55:15.266 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'myrulestest.rules'
2018-10-03 12:55:15.487 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-10-03 12:55:15.847 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'myhometest.sitemap'
2018-10-03 12:55:16.856 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-10-03 12:55:17.025 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-10-03 12:55:17.102 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin

Thanks for help and greets
Alex

I checked your rule and everything works after going to basicUi and first turning on then off each switch. This changes the switch from NULL to a value. After that when I switch SW1 to on then SW3 turns on as well.

Have you tried turning all switches on the off?

The keyword was BasicUI.
I always accessed the sitemap from HABmin. From there it still seems not to work. Using BasicUI, everything works as expected.

Initializing the variables on start-up is still a good idea.

Thanks!

I checked in Habmin and it works. After turning on SW1 hit F5 to refresh.

Item SW1 changed to ON
allows you to ignore the previous state (NULL at start up)

Reloading HABmin causes some strange behaviour, like switches without any rules behind changing their state. Might be an issue of my browser (Firefox with a few addons). But as long as it works with BasicUI…