Developers: New Item type(s) wanted

I had a failed HDD and am setting up a new clean installation. It will take somewhat longer.

Dear All

Iā€™m new to openhab comunity as I have just started building my own openhab interface. During my configuration I also encountered the same problem as brhar so I decided to post under this topic and maybe get a tip how to go around my problem. In my project I want to have everything organized on different pages. On the main page I want to have a room button that opens a new page with some switches and sensor readings, and inside the room page I want a additional button that will send me to another sub menu containing a set off new switches. To this point I have managed to build my sitemap and items files and everything works(Screenshots at the bottom)

And now here is the problem that brhar encountered. I would like to have a selection drop list or any other means to select a string on the third page. Sitemap build only enables to have a a main group and one subgroup. Any other nesting causes problems. My method is based on the same principal as brhar and itā€™s based on groups concept in the item file (I build my configuration based on the demo configuration that also uses the same method). When using the groups method you canā€™t use the selection option as it is only available in the sitemap configuration. And here is the main question is it posible to have a selection list on a third page using sitmap configuration.
Below is my sitemap and items configuration:


Group All 	(All)
Group Outdoor 	(All)
Group Shutters 	(All)
Group Weather 	(All)
Group Status 	(All)

Group Room_1 		"Pokoj_1" 		 <bedroom> 	(All)
Group RGB_Room_1	"RGB_Pokoj_1" <bedroom>	(Room_1)
Group Room_2 		"Pokoj_2" 		<office> 	        (All)
Group Livingroom 	"Salon" 		<video> 	        (All)
Group Kitchen 		"Kuchnia" 		<kitchen> 	        (All)
Group Toilet 		"Toaleta" 		<bath> 		(All)
Group Corridor_1 	"Korytarz_1"      <corridor> 	(All)
Group Corridor_2 	"Korytarz_2"      <corridor> 	(All)
				
/* active groups */
Group:Switch:OR(ON, OFF) 		Lights 		"All Lights [(%d)]" 							(All)
Group:Switch:OR(ON, OFF) 		Heating 	"No. of Active Heatings [(%d)]" 		<heating> 		(All)
Group:Number:AVG 			Temperature	"Avg. Room Temperature [%.1f Ā°C]" 		<temperature>		(Status)
Group:Contact:OR(OPEN, CLOSED) 		Windows 	"Open windows [(%d)]"				<contact>		(All)

// RGB

Color RGB_Room_1_value                  "RGB" <slider>          (RGB_Room_1)
String RGB_Room_1_Command 					        (RGB_Room_1_value) {mqtt=">[broker:bruh/porch/set:command:*:default]"}
Dimmer RGB_Room_1_Brightnes 	"RGB Jasnosc" 		(RGB_Room_1)

/* Lights */
Dimmer Light_Livingroom_Table 		"Table" 		(Livingroom, Lights)

Switch Light_Kitchen_Ceiling 		"Ceiling" 		(Kitchen, Lights)
Switch Light_Kitchen_Table 		"Table" 		(Kitchen, Lights)

Switch Light_Corridor_2_Wardrobe 	"Wardrobe"	(Corridor_2, Lights)
Switch Light_Corridor_2_Ceiling 	        "Ceiling" 		(Corridor_2, Lights)

Switch Light_Toilet_Ceiling 		"Ceiling" 		(Toilet, Lights)
Switch Light_Toilet_Mirror 		"Mirror" 		(Toilet, Lights)

Switch Light_Corridor_1_Ceiling 	"Ceiling" 		(Corridor_1, Lights)

Switch Light_Room_1_Ceiling 	"Zyrandol" 		(Room_1, Lights) { mqtt=">[broker:cmnd/Light1/power:command:*:default], <[broker:stat/Light1/POWER:state:default]" }

Switch Light_Room_1_Lamp 	"Lampka" 		(Room_1, Lights) { mqtt=">[broker:cmnd/sonoff1/power:command:*:default], <[broker:stat/sonoff1/POWER:state:default]" }

Switch Light_Room_2_Ceiling 		"Pokoj_2" 		(Room_2, Lights)

Switch Light_Outdoor_Garage 		"Garage" 		(Outdoor, Lights)
Switch Light_Outdoor_Terrace 		"Terrace" 		(Outdoor, Lights)
Switch Light_Outdoor_Frontdoor 		"Frontdoor"		(Outdoor, Lights)

/* Heating */
Switch Heating_Room_1 		"Pokoj_1" 		<heating>	(Room_1, Heating)
Switch Heating_Room_2 		"Pokoj_2" 		<heating>	(Room_2, Heating)
Switch Heating_Corridor_2 	"Korytarz_1" 		<heating>	(Corridor_2, Heating)
Switch Heating_Corridor_1 	"Korytarz_2" 		<heating>	(Corridor_1, Heating)
Switch Heating_Toilet 		"Toaleta"	 	<heating>	(Toilet, Heating)
Switch Heating_Livingroom 	"Salon" 		<heating>	(Livingroom, Heating)
Switch Heating_Kitchen 		"Kuchnia" 		<heating>	(Kitchen, Heating)



/* Rollershutters */
Switch Shutter_all (Shutters)

Rollershutter Shutter_Toilet 		"Toaleta"	(Toilet, Shutters)
Rollershutter Shutter_Kitchen 		"Kitchen"	(Kitchen, Shutters)
Rollershutter Shutter_Livingroom 	"Salon"		(Livingroom, Shutters)
Rollershutter Shutter_Room_1		"Pokoj_1"	(Room_1, Shutters)
Rollershutter Shutter_Room_2		"Pokoj_2"	(Room_2, Shutters)


/* Indoor Temperatures */
Number Temperature_Corridor_2 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, GF_Corridor_2)
Number Temperature_Toilet 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, GF_Toilet)
Number Temperature_Livingroom 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, GF_Livingroom)
Number Temperature_Kitchen 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, GF_Kitchen)
Number Temperature_Bath 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, FF_Bath)
Number Temperature_Office 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, FF_Office)
Number Temperature_Child 	"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, FF_Child)
Number Temperature_Bed 		"Temperature [%.1f Ā°C]"	<temperature>	(Temperature, FF_Bed)

/* Windows */
Contact Window_Frontdoor 	"Frontdoor [MAP(en.map):%s]"		(Corridor_2, Windows)
Contact Window_Kitchen 		"Kitchen [MAP(en.map):%s]"		(Kitchen, Windows)
Contact Window_Livingroom 	"Terrace door [MAP(en.map):%s]"	(Livingroom, Windows)
Contact Window_Toilet 		"Toaleta [MAP(en.map):%s]"		(Toilet, Windows)
sitemap demo label="SzensziHome"
{
	Frame {
		Group item=Room_1 		label="Pokoj_1" 	icon="bedroom"
		Group item=Room_2		label="Pokoj_2" 	icon="office"
		Group item=Livingroom 		label="Salon" 		icon="video"
		Group item=Kitchen		label="Kuchnia" 	icon="kitchen" 	
		Group item=Toilet  		label="Toaleta" 	icon="bath" 
		Group item=Corridor_1 		label="Korytarz_1" 	icon="corridor"
		Group item=Corridor_2 		label="Korytarz_2" 	icon="corridor"
		Group item=Lights 		label="Swiatla" 	icon="bedroom"
		
		}
}

You did not define a group RGB_Room_1_value, but you did refer to it. Instead of, RGB_Room_1_value is a color itemā€¦

The point is, you want to ā€œauto buildā€ a sitemap through group items.
This will work, but the output will be some sort of standard, but not a specialized sitemap.

The .items file is not meant to generate more or less ā€œcompleteā€ sitemaps, this is what you do with the .sitemap-file.
You can use groups to get a minimal sitemap, but to build a complete sitemap with all special details, you will have to build it from scratch.
Please keep in mind, that sitemaps are only one way to build an UI, and every user has itā€™s own idea of ā€œthe right wayā€ to build an UI.

sitemap demo label="root" {
    Frame label="root, 1. Frame" {
        Text label="root, 1.Frame, 1. Item, no link"
        Text label="root, 1.Frame, 2. Item, link" {
            Frame label="1. sub page, 1.Frame" {
                Text label="1. sub page, 1. Frame, 1. Item, no link"
                Text label="1. sub page, 1. Frame, 2. Item, link" {
                    Switch item=myNumber mappings=[1="1",2="two",3="3",4="four"]
                }
            }
        }
    }
    Frame label="root, 2. Frame" {
        Text label="root, 2.Frame, 1. Item, no link"
        Text label="root, 2.Frame, 2. Item, link" {
            Frame label="2. sub page, 1.Frame" {
                Text label="2. sub page, 1. Frame, 1. Item, no link"
                Text label="2. sub page, 1. Frame, 2. Item, link" {
                       Selection item=myNumber mappings=[1="1",2="two",3="3",4="four"]
             }
            }
        }
    }
}

You can nest this to any deep without any issues (well, I use it to 5. levelā€¦ House(level)->room->device->function->options.)

As you can see, I did different widgets to the very same item. If I had to set the widget in .items File, this wouldnā€™t be possible (or at least I would have to override the behavior, formally set as default in .items file (as I can do it for labels)

In fact, it would be nice to have the possibility, but itā€™s no issue not to be able to configure a default widget for each item.

4 Likes

Thank you Udo for your reply. It helps a lot.

As mentioned Iā€™m a total bigener in the OpenHab so my Ui is based on the demo files modified. I tried to define a Sitemap with multi nesting but had issues. Now hopefully with your example I will be able to build a proper sitemap file not based on the auto building. As to the RGB_Room_1_value it is defined in the Rules file. This item is meant to generate a string of values that will be later sent via MQTT to the device.


import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
import java.util.*
import org.openhab.core.library.types.*

// WybĆ³r koloru


var HSBType hsbValue
var int redValue
var int greenValue
var int blueValue
var String RGBvalues

rule "Set RGB 2 value"
 when
 Item RGB_Room_1_value changed
 then
 hsbValue = RGB_Room_1_value.state as HSBType


 redValue = hsbValue.red.intValue 
 greenValue = hsbValue.green.intValue 
 blueValue = hsbValue.blue.intValue 


 logInfo( "RGB_Room_1_value", RGBvalues )
RGBvalues= "r" + ":" + redValue.toString + "," + "g" + ":" + blueValue.toString + "," + "b" + ":" + greenValue.toString

sendCommand( RGB_Room_1_Command , "{" + "state" +":" + "ON" +"," + "color" + ":" + "{" + RGBvalues + "}" + "," + "brightness" + ":" + "255" + "," + "effect" + ":" + "solid" + "}")
end


// Work with a list of selected Sonoff modules
val sonoff_device_ids = newArrayList(
    "sonoff1",
    //... add all your modules here!
    "sonoff1"
)

rule "Sonoff Maintenance"
when
    Item Sonoff_Action received command
then 
    logInfo("sonoff.rules", "Sonoff Maintenance on all devices: " + receivedCommand)
    for (String device_id : sonoff_device_ids) {
        switch (receivedCommand) {
            case "restart" :
                publish("broker", "cmnd/" + device_id + "/restart", "1") 
            case "queryFW" :
                publish("broker", "cmnd/" + device_id + "/status", "2")
            case "upgrade" : {
                publish("broker", "cmnd/" + device_id + "/otaurl", "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin")
                publish("broker", "cmnd/" + device_id + "/upgrade", "1")
            }
        }
    }
    Sonoff_Action.postUpdate(NULL)
end

I would also like to ask a different question. If I switch to the sitemap build based Ui than what kind of item would allow me to change a value between 0-255?. I have tried dimmer but it doesnā€™t support decimal values. What kind of item would allow me to use a slider like item to modify values?

Setpoint item in sitemap linked to a Number item should do the trick!

Setpoint item=YourNumberItem minValue=0 maxValue=255 step=1

For slider you can use:

Slider item=YourDimmerItem

BR,
George

2 Likes

Yes, Slider is only 0 to 100. It depends on what is the goal. If you want a rough trim through the values 0 to 255, you can use Setpoint with a step size of 8 or 16. Sometimes you donā€™t even need more than 4 or five different steps, then I would suggest a mapping or selection. If you want a Slider, you can do it through an unbound item:
.items

Number myRealItem {...whatever binding}
Number myUIItem "My Item is [%d %%]"

.rules

rule "myUIItem"
when
    Item myUIItem received command
then
    if (myUIItem.state instanceof DecimalType)
        myRealItem.sendCommand(((myUIItem.state as DecimalType).intValue * 2.55).intValue)

.sitemap

Slider myUIItem

this will give you a slider. Whenever you change the Slider, openHAB will trigger the rule, which will send a Value between 0 and 255.

1 Like

Thank you Guys for all the help. Thanks to all advices Iā€™m on a good way to properly set my new UI and building my home automation system.

Guys

Is there any way to make a normal one state button in the sitemap? I need to make a panel for a IR remote controller and I need to make a normal button, not a two state switch.

There you go :wink: http://docs.openhab.org/configuration/sitemaps.html#element-type-switch

Switch item=WZ_PC_WakeOnLAN label="Command" mappings=[ON="Wake Up"]

Unfortunately Iā€™m looking for something else. I donā€™t want a switch because it works like on/off. I need a button. You press it and it dose a specified action and then returns to normal.

Unfortunately, this type of widget that only sends an impulse does not exist yet. But there is an issue (with a quite long discussion) in the Smarthome repo:

I use switches for this behavior all the time. You press the button created by the mappings which sends the command ON to the Switch. Then either the binding connected to the Switch or a Rule does the push button action (e.g. open the garage door). If desired one can then either set it back to OFF using the Expire binding or a Rule, but there really isnā€™t a whole lot of reason to. I just leave my switch always ON and treat the new ON commands as the signal the button was pressed.

It may not be as straightforward as a separate widget but it works well.

I donā€™t see why my solution doesnā€™t solve your issue.

If you want to have the button to pop out after being pressed, try using autoupdate="false" as a binding:

Switch MyButton "My Button" {mybinding="...", autoupdate="false"}
Switch item=MyButton mappings=[ON="Go!"]

The button should pop out after being pressed, as openHAB will not postUpdate the state of MyButton to ON
If this does not work as expected, you can use the expire binding to automatically postUpdate an OFF to MyButton as well:

Switch MyButton "My Button" {mybinding="...", expire="1s,OFF"}

Be aware that sometimes the UI will need some time to display these changes correctly.

1 Like