Virtual button/switch as rule trigger?

I would like to have a virtual button or switch on the app that would trigger a rule. I’ve looked but can’t find a way to do this. Any help would be appreciated. Thanks!

not that difficult.

just define a switch item like:

switch Rule_Trigger "Rule Trigger"

and then a rule:

rule "rule triggered by RULE TRIGGER"

when 
	Item Rule_Trigger received update
then
	if (Rule_Trigger.state == ON) {
		sendCommand(Shutter_OG_Sleeping, UP)
	}
	if (Rule_Trigger.state == OFF) {
		sendCommand(Shutter_OG_Sleeping, DOWN)
	}
end

or any other action.

and add the switch to the sitemap

cheers
Karsten

I appreciate the help! I’ll have to try this out. As Plato wisely said, “the beginning is half the work.”

I got it working! Thanks so much. Off to rule my house….

1 Like

I’m not sure what I’m doing wrong…

sitemap file:

sitemap home label="Testing"
{
    Frame label="CTA Information" {
                Switch          item=CTAtracker
        }
}

Items file

Switch  CTAtracker      "Start CTA Tracking"    (CTA)           <hue>

Log:

04:45:07.229 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'CTAtracker' for widget org.eclipse.smarthome.model.sitemap.Switch
04:45:07.239 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'CTAtracker' for widget org.eclipse.smarthome.model.sitemap.Switch
04:45:07.246 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch

This should be a very simple virtual switch…

What am I missing?

1 Like

Take a look at the correct syntax for an item definition:

So you need to change your items file to:
Switch CTAtracker "Start CTA Tracking" <hue> (CTA)

@sihui Hmm… I tried your suggestion by switching and (CTA), but when loading the sitemap I get this:

log:

11:41:51.139 [WARN ] [basic.internal.render.SwitchRenderer] - Cannot determine item type of 'CTAtracker'
org.eclipse.smarthome.core.items.ItemNotFoundException: Item 'CTAtracker' could not be found in the item registry
        at org.eclipse.smarthome.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:146)[98:org.eclipse.smarthome.core:0.8.0.b5]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getItem(ItemUIRegistryImpl.java:605)[131:org.eclipse.smarthome.ui:0.8.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.SwitchRenderer.renderWidget(SwitchRenderer.java:58)[179:org.eclipse.smarthome.ui.basic:0.8.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.renderWidget(PageRenderer.java:171)[179:org.eclipse.smarthome.ui.basic:0.8.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:128)[179:org.eclipse.smarthome.ui.basic:0.8.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:149)[179:org.eclipse.smarthome.ui.basic:0.8.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processPage(PageRenderer.java:92)[179:org.eclipse.smarthome.ui.basic:0.8.0.b5]
        at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:157)[179:org.eclipse.smarthome.ui.basic:0.8.0.b5]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[81:org.eclipse.jetty.servlet:9.2.14.v20151106]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[81:org.eclipse.jetty.servlet:9.2.14.v20151106]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)[165:org.ops4j.pax.web.pax-web-jetty:4.2.4]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[79:org.eclipse.jetty.security:9.2.14.v20151106]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:271)[165:org.ops4j.pax.web.pax-web-jetty:4.2.4]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[81:org.eclipse.jetty.servlet:9.2.14.v20151106]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[165:org.ops4j.pax.web.pax-web-jetty:4.2.4]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.Server.handle(Server.java:499)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[80:org.eclipse.jetty.server:9.2.14.v20151106]
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[72:org.eclipse.jetty.io:9.2.14.v20151106]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[83:org.eclipse.jetty.util:9.2.14.v20151106]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[83:org.eclipse.jetty.util:9.2.14.v20151106]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
11:41:51.163 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'CTAtracker' for widget org.eclipse.smarthome.model.sitemap.Switch
11:41:51.166 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
11:41:51.176 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'CTAtracker' for widget org.eclipse.smarthome.model.sitemap.Switch
11:41:51.181 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
11:41:51.185 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'CTAtracker' for widget org.eclipse.smarthome.model.sitemap.Switch
11:41:51.188 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'CTAtracker' for widget org.eclipse.smarthome.model.sitemap.Switch

items:

Switch  CTAtracker      "Start CTA Tracking"    <hue>   (CTA)

sitemap:

sitemap home label="Testing"
{
Frame label="CTA Information" {
       Switch          item=CTAtracker
        }
}

No luck :frowning: I don’t understand. Is it because I don’t have a binding attached to the item?

No. A virtual item is not attached to any binding.

Try removing the spaces between Switch and item, maybe that is the problem.
And look for the correct syntax for frame defintions in sitemaps, you may try:

sitemap home label="Testing"
{
Frame {
Text label="CTA Information"
                {
                Switch item=CTAtracker
                }
       }
}

I would like to come back to this topic. I wanted to establish a virtual switch to activate some rules later on via HabPanel … e.g. a rule which is only active if I want to have presence simulation.
Up to now I try to initatiate the item by

switch VI_ruletrigger "VI_ ruletrigger "

after that I expect to see it in OpenHab to generate a switch with it in the UI.
As this did not work I remembered that it may be need to have a first manipulation of the item to be visible so I integrated a rule:

rule "trigger init"
when
    System started
then
    sendCommand(VI_ruletrigger, OFF)
end

but also now, after restart of OpenHab I do not see the item, neither in HabPanel nor in PaperUI.
Anyone an idea?

Greetings
Sven

Switch should have an upper-case S as in:

Switch VI_ruletrigger "VI_ ruletrigger"

I’d get rid of the trailing zero in your label too but that’s not essential.