[SOLVED] Emulate a simple switch On Off

  • Platform information:
    • Hardware: Rasberry PI 4
    • OS: openHABian
    • Java Runtime Environment: OpenJDK Java 8
    • openHAB version: 2.4
  • Issue of the topic: Subscription to events

hi, good evening at all!
I need to know if i can emulate a simple switch on off.

My problem is to test event, but now i don’t have sensor :cry:

The sensors will arrive next week but I would like to try
some tests for intercept the events.

I thought of a simple zigbee button, is possible?

Thanks

You can create a virtual switch Item and have the rule (I assume DSL rules) trigger on changes.
The Item would look like this:

Switch  vZigbeeTest "Zigbee virtual test switch"

And a rule that triggers when you ‘flip the switch’:

rule "Zigbee Switch test rule"
when
    Item vZigbeeTest changed
then
    if (vZigbeeTest.state == ON)
        // do stuff...
    else ...   
end

The virtual switch can be operated for instance by adding it to the sitemap for Basic UI or via the Karaf console.

1 Like

To expand on Ron’s reply a bit. One of the main benefits to having a separation between Things and Items is that you can build your Items independently of the Things.

So build your Items as if you actually had the device. Just leave them unlinked. Build your sitemap or Rules as you need them. Then you can command or update the Item using:

  • another Rule you use for testing
  • the sitemap
  • the Karaf console
  • the REST API Docs

When you get the device and get it working with OH, then all you need to do is link the Channel on the Thing to the Item and you are done.

1 Like

Very thanks!
i have tryed to i see the status change in the rest call “GET /items/{itemname}/state” and Works :slight_smile:

Great!
Hope your sensors will arrive soon. ;o)