read-only Switches?

2,379 views
Skip to first unread message

Carsten Wimmer

unread,
Jan 7, 2014, 2:31:32 PM1/7/14
to ope...@googlegroups.com
Hi,

is there a way to declare a switch, that is declared in a sitemap, as read-only?

ie. if I want to express some state of the system using a Switch, it has no effect to manually change its state anyway.
It does not hurt that it is changeable/switchable, but it would be way nicer to show it deactivated/read-only.

I did not find anything suitable in the Wiki.

Or is there a better way to express states of anything?  ie. a Number that is rendered in a nice way by using some mapping? ( ie. 0==no_fire.png, 1==fire.png )


Thanks and best regards,
Carsten

Ben Jones

unread,
Jan 7, 2014, 2:36:24 PM1/7/14
to ope...@googlegroups.com
Yep very simple - just use the Text widget, in your sitemap, for the switch item.

example.items
Switch TestSwitch "Test Switch [%s]" { somebinding }

example.sitemap
Text item=TestSwitch

Carsten Wimmer

unread,
Jan 7, 2014, 3:32:06 PM1/7/14
to ope...@googlegroups.com
Thanks Ben, that works fine.

Using the Text widget, can I map "OFF" and "ON" (these are the Switch item's states) to anything else?

The Wiki documentation regarding site maps only offers mapping for the Switch widget, not for Text.

Ben Jones

unread,
Jan 7, 2014, 3:35:51 PM1/7/14
to ope...@googlegroups.com
Yes, by using a MAP in the item display field;

Switch TestSwitch "Test Switch [MAP(example.map):%s]" { somebinding }

where example.map is found in your /transform directory;

ON=ARMED
OFF=DISARMED

Carsten Wimmer

unread,
Jan 7, 2014, 4:11:05 PM1/7/14
to ope...@googlegroups.com
Ok, so the Mapping should be added to the items file, Not the Sitemap file where I looked.
Along with Dynamic colors this is a nice combo. Thanks again!

maihacke

unread,
Jan 8, 2014, 3:01:59 AM1/8/14
to ope...@googlegroups.com
I had the same problem. This really should be documented in the samples or in the wiki.

Carsten Wimmer

unread,
Jan 10, 2014, 4:11:11 PM1/10/14
to ope...@googlegroups.com
When defining a switch for itself with a Text widget, this all works fine.

But what if I put a whole (automatic) group into the sitemap? Then there is no way to attach a Text widget to all these, instead a Switch widget is used as default.

Any way to get Text widgets in there as well?

Ben Jones

unread,
Jan 10, 2014, 5:12:41 PM1/10/14
to ope...@googlegroups.com
I don't think using groups in sitemaps is actively encouraged. It is more to make demos easier, but for any 'real world' installs you should manually define each item in your sitemaps.

Otto Tronarp

unread,
Jan 11, 2014, 2:08:46 AM1/11/14
to ope...@googlegroups.com
Why, I have only been trying out openHAB for ~2 weeks now so I'm probably missing something, but so far it feels like a good group hierarchy can save you a lot of typing with the site map file.

One thing I'm missing though is a way to flatten Groups, so you could do something like

Group:Number:AVG GF_Temperature "Ground floor [%.2f]" <temperature>

Number GF_LiviningRoom_Temp "Living room [%.2f]" (GF_Temperature)
Number GF_Kitchen_Temp "Kitchen [%.2f]" (GF_Temperature)

Text item=Temperature {
  Frame label="Current" {
    FlatGroup item=GF_Temperature //Should give a flat listing of the group
  }
  Frame label="History" {
   Chart item=Temperature period=W
  }
}

That would be really convenient I think.

Otto

Carsten Wimmer

unread,
Jan 13, 2014, 3:06:17 PM1/13/14
to ope...@googlegroups.com
Okay, I have defined everything now.

What I am wondering is that I need a special rule to update the "systemwide low battery status" (Lowbat_systemwide) programmatically or if there is some automatism available:

main.items:
...
Group Lowbat (All)

Switch Lowbat_SD_Treppenhaus "LOWBAT Treppenhaus Rauchmelder [%s]" <siren> (Lowbat) {homematic="id=myididid1, channel=0, parameter=LOWBAT, converter=BooleanOnOffConverter"}
Switch Lowbat_SD_OG_Room "LOWBAT OG Room Rauchmelder [%s]" <siren> (Lowbat) {homematic="id=myididid2, channel=0, parameter=LOWBAT, converter=BooleanOnOffConverter"}

Switch Lowbat_systemwide "Battery status [%s]" <siren>
...

main.sitemap:
...
Frame label="System status" {
  Text item=Lowbat_systemwide {
    Text item= Lowbat_SD_Treppenhaus
    Text item= Lowbat_SD_Room
  }
}
...

And a rule (not optimized, but working):
rule "lowbat monitoring"
when
        Item Lowbat changed
then
        var Boolean seenLowbat = false
        Lowbat?.members.forEach[dev|
                if(dev.state == ON) seenLowbat=true
        ]

        if(seenLowbat==true)
                postUpdate(Lowbat_systemwide, ON)
        else
                postUpdate(Lowbat_systemwide, OFF)
end

I want the Lowbat_systemwide item's siren icon to change when one of my battery devices creates a low battery event.
The rule and everything works fine, as I said: I am just wondering if there is a simpler or automatic way to achieve such things..

Also feel free to comment my rule (to make it nicer, or if it has any illegal things;  I am new to Xtext/Xbase).

Thanks!

Ben Jones

unread,
Jan 13, 2014, 3:14:05 PM1/13/14
to ope...@googlegroups.com
Pretty sure something like;

Group:Switch:OR(ON, OFF) Lowbat "Battery status [%s]" <siren> (All)

Switch Lowbat_SD_Treppenhaus "LOWBAT Treppenhaus Rauchmelder [%s]" <siren> (Lowbat) {homematic="id=myididid1, channel=0, parameter=LOWBAT, converter=BooleanOnOffConverter"}
Switch Lowbat_SD_OG_Room "LOWBAT OG Room Rauchmelder [%s]" <siren> (Lowbat) {homematic="id=myididid2, channel=0, parameter=LOWBAT, converter=BooleanOnOffConverter"}

Will do the trick with no need for any rules. And replace Lowbat_systemwide with Lowbat in your sitemap.

What this group definition, Group:Switch:OR(ON, OFF), says is "if any group member is ON then the group item is ON, otherwise it is OFF". 

Alternatively, something like Group:Switch:AND(ON, OFF) means "if all group members are ON then the group item is ON, otherwise it is OFF".

The group stuff is quite powerful once you get your head around it. Means you can simply add low battery items to that group and not have to change anything downstream.

Carsten Wimmer

unread,
Jan 13, 2014, 3:45:44 PM1/13/14
to ope...@googlegroups.com
This is just plain awesome, thanks!

Carsten Wimmer

unread,
Jan 14, 2014, 2:45:39 PM1/14/14
to ope...@googlegroups.com
Tried it today, works very good. Thanks!

I saw that I have a group called "Rollershutters", and (of course) all my roller shutters are members of this group.
In the sitemap I have a line:
  Group item=Rollershutters icon="rollershutter"
and all is automatically added in the web app.  The icon of this group even shows if everything is down/closed, or up/open or a state in between.

So what I did now with Group:Switch:OR(ON,OFF) can be automatically done as well.
But then, again, for my switch example I would get switch widgets in my auto-generated list, not text widgets as I am doing now manually.

Is there a documentation available, describing all the details regarding manual/auto grouping etc?    basically the stuff we are discussing here..



Am Dienstag, 7. Januar 2014 20:31:32 UTC+1 schrieb Carsten Wimmer:

Ben Jones

unread,
Jan 14, 2014, 2:49:58 PM1/14/14
to ope...@googlegroups.com
You can't control how group items are displayed in the UI if you just specify the group as you are doing. That is why I would suggest you add each item individually to your sitemap as then you can make it readonly, change text, icon, etc.

Carsten Wimmer

unread,
Jan 14, 2014, 3:06:13 PM1/14/14
to ope...@googlegroups.com
Yep, that is what I am doing when I do not want the standard widget for the items (ie. text widgets for showing the read-only status for my smoke detectors, which are switch items).

If the standard widget is fine (ie. for my roller shutters) I can just use the automatic groups.

nattila

unread,
Jul 27, 2015, 4:21:25 PM7/27/15
to ope...@googlegroups.com, carst...@gmail.com
I would like to create a read-only switch also, but my simpliest code does't work. In my sitemap I display same item value twice. Once as a Switch and once as a Text item. the Swith item works great, but the Text item has no value. Do you have any idea why?

my items file
...
Switch Ariston_Boiler "Kazan"
           (Heating)

my sitemap
sitemap custom label="Otthon"
{
       
Frame {
                ...
               
Switch item=Ariston_Boiler
               
Text item=Ariston_Boiler
       
}
}


Reply all
Reply to author
Forward
0 new messages