Man/Auto mode switch

I’m not sure that it’s possible to define a default value with in a sitemap. You could create a rule to update the value when your system starts. Do you have any persistence configured?

Example first-use rule.

// Initialize
rule "Light timings init"
when
    System started
then
          // only need populating before first use
          // usually get restore-on-startup
    if (vnm_Tperim.state == NULL) { vnm_Tperim.postUpdate(15) }
end

If you later choose to persist and restore this Item, it should get restored before the rule runs and not get initialized.

You can’t.

Yes. Or a Number (it’s easy to map 0, 1, 2 etc. to text for display)

1 Like

sorted it , thanks , used a proxy item to hold the 3 way state and a rule to check for changes to the proxy state.

But

I have a heating icon on the sitemap setpoint when 3 way switch in ON, the range of values from 10 to 25C , but the heating icon requires 0-100 probably, so can I scale the setpoint in the sitemap but leave its inherent value unscaled so that my rules dont need chaning.?
Cheers

EDIT:
Sorted, I will use visibility attribute on the sitemap widget and map these to the same item but different icons.

It’s a lot easier to make a custom icon set.

1 Like

yep, done, thanks

For more detail on rossko57’s answer, there’s a DP for that: Design Pattern: Encoding and Accessing Values in Rules, Approach 2.

I’ve also some approaches that work only with Scripted Automation, not Rules DSL. You can put a default value into the Item metadata and have a system started Rule that reads that metadata and updates the Item with it’s value. My Ephemeris Time of Day implementation uses this approach to initialize some Items to define static start times.

The heating icon uses ON and OFF only. Not a range. There is no representation in the icon for “AUTO”.

@rlkoshak is there any way to use the classic iconset , so that the fire icon is “on” if the sitemap proxy item switch widget (ON, OFF, AUTO) = ON or AUTO.
The fire icon correctly “turns on” when switch = ON, and off when switch = OFF, as per your assertion above, but can I refer to the classic icon in my sitemap mapping , because it seems they are enclosed in .jar files under the /var/lib/openhab2 tree, and you know how much I dislike anything with jar in :slight_smile: :slight_smile:

EDIT: Sorry, the sitemap widget:

Switch 		item=i_HVAC_CH_Switch_Proxy			label="Central heating mode" 			icon="fire"		mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] 

There are no icons under my $OPENHAB_CONF/icons/classic/ , guess they are embedded somewhere?

The icon chosen is based on the state of the Item. Period. If you need to control the icon based on any other states you need to create your own set of dynamic icons that work with the states of your Items. You cannot base the icon on the label or any other transformation of the Item’s state.

Jar files are just zip files and can be opened and manipulated using any zip program. So you can extract them using gunzip or your zip tool of choice, or download them from https://www.openhab.org/docs/configuration/iconsets/classic/#icons or from your actual sitemap (right click and save image as) or find your own icons on the web to use. There are some great icon sets freely available for non-commercial use.

1 Like

purfect , as always , thanks @rlkoshak … jeez, if you were only paid for supporting this platform eh :roll_eyes: :grinning:)

well @rlkoshak it’s a bit tricky this one in the sitemap , maybe it’s not possible…

i have the switch widget mapped to ON, OFF, AUTO using a proxy item moding a heating boiler Swich Item (on / off) Left to the widget is the :fire: icon.
I want fire on if switch is ON and off if switch OFF , okay easy.

So if i use custom icon solution, and when switch is in AUTO mode, how do i set fire icon on only if the boiler switch is On.

Reason: the icon shows off a demand for water is set, it can be on or off in AUTO because a rule is comparing room stat with desired temp and toggling the boiler on/off accordingly in AUTO.

??


Switch item=i_HVAC_CH_Switch_Proxy label="Central heating mode" icon="fire-on" mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] visibility=BoilerItem==ON]

Switch item=i_HVAC_CH_Switch_Proxy label="Central heating mode" icon="fire-off" mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] visibility=BoilerItem==OFF]

1 Like

For another example of Hans-Jörg’s example see my post above for the Garage Door openers. But note that I had to create my own copies of the icons. I never was able to get it to work with the built icons. I’ve also not looked at it in years, maybe it works better now.

1 Like

I am using it for displaying different battery icons using standard icon-set, working fine.

always a clever sod thinking out of the box lol :+1::grin:

I’m not convinced that works in all of the different sitemap based UIs, since it “breaks the rules” by specifying a hyphen in the target icon name. That part is supposed to be worked out by the icon picker service, and if it goes wrong it would be looking for fire-on-on.svg or something. Maybe when that failed it fall back to a default fire-on.svg and appear to work after all.
I don’t know, Im sure this used to be trouble.

The example given with fire-on/fire-off icon is exactly what I use for displaying my boiler state and it is working absolutely fine with basic and classic UI.

@hmerk @rlkoshak can you help with this please… I’ve stared at this many times and cannot see what is wrong with this:…

		Switch 		item=i_HVAC_CH_Switch_Proxy			label="Central heating"	 				icon="fire-on"			visibility=[i_HVAC_CH_Switch == ON]			mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] 
		Switch 		item=i_HVAC_CH_Switch_Proxy			label="Central heating" 				icon="fire-off"		visibility=[i_HVAC_CH_Switch == OFF]		mappings=[ON="ON",OFF="OFF",AUTO="AUTO"] 

The fire-on is displayed even when i_HVAC_CH_Switch == OFF and i_HVAC_CH_Switch_Proxy == AUTO

??

Rule

rule 
    "HVAC_CH"
when
    Item g_TRV_Actual_Temperature changed 
    or
    Item g_TRV_Set_Temperature changed 
    or 
    Item i_HVAC_CH_Switch_Proxy changed
then 
    // Check if boiler can be turned OFF or ON in Auto mode
    if (i_HVAC_CH_Switch_Proxy.state == "AUTO") {
        
        
        var Number temperature = g_TRV_Actual_Temperature.state as Number
        var Number demand = g_TRV_Set_Temperature.state as Number
        val Number hysteresis = 0.5

        logInfo("HVAC_CH_Off.rules", "CH AuTO mode checking...")
        logInfo("HVAC_CH_Off.rules", "...temperature={} demand={}", temperature, demand)
        logInfo("HVAC_CH_Off.rules", "...using hysteresi, go ON  if temp < {}", (demand - hysteresis))
        logInfo("HVAC_CH_Off.rules", "...using hysteresi, go OFF if temp > {}", (demand + hysteresis))
        
        if (temperature < (demand - hysteresis)) {

            // Turn on
            i_HVAC_CH_Switch.sendCommand(ON)
            logInfo("HVAC_CH.rules", "...CH turned ON by AUTO rule") 
         
        } else if (temperature > (demand + hysteresis)) {
                
            // Turn Off
            i_HVAC_CH_Switch.sendCommand(OFF) 
            logInfo("HVAC_CH.rules", "...CH turned OFF by AUTO rule")
        }
        
    } else if (i_HVAC_CH_Switch_Proxy.state == "ON") {

            // Turn ON by user demand
            i_HVAC_CH_Switch.sendCommand(ON) 
            logInfo("HVAC_CH.rules", "CH turned ON by rule")

    } else if (i_HVAC_CH_Switch_Proxy.state == "OFF") {
        
            // Turn ON by user demand
            i_HVAC_CH_Switch.sendCommand(OFF)
            logInfo("HVAC_CH.rules", "CH turned OFF by rule")
    }
    
     

/*
    //Check if boiler needs to be turned ON 
    if (i_HVAC_CH_Switch.state == OFF && (g_TRV_Actual_Temperature.state < g_TRV_Set_Temperature.state)) {
        i_HVAC_CH_Switch.sendCommand(ON)
        logInfo("HVAC_CH.rules", "CENTRAL HEATING turned ON by rule")
    } 
*/
end

events.log

020-01-16 12:37:49.342 [vent.ItemStateChangedEvent] - i_HVAC_CH_Switch_Proxy changed from ON to OFF
2020-01-16 12:37:49.361 [ome.event.ItemCommandEvent] - Item 'i_HVAC_CH_Switch' received command OFF
2020-01-16 12:37:49.387 [nt.ItemStatePredictedEvent] - i_HVAC_CH_Switch predicted to become OFF
2020-01-16 12:37:49.413 [vent.ItemStateChangedEvent] - i_HVAC_CH_Switch changed from ON to OFF
2020-01-16 12:37:50.120 [ome.event.ItemCommandEvent] - Item 'i_HVAC_CH_Switch_Proxy' received command AUTO
2020-01-16 12:37:50.134 [vent.ItemStateChangedEvent] - i_HVAC_CH_Switch_Proxy changed from OFF to AUTO
2020-01-16 12:37:50.198 [ome.event.ItemCommandEvent] - Item 'i_HVAC_CH_Switch' received command OFF
2020-01-16 12:37:50.225 [nt.ItemStatePredictedEvent] - i_HVAC_CH_Switch predicted to become OFF
[12:41:34] openhabian@openhab:~$

openhab.log

2020-01-16 12:37:50.155 [INFO ] [thome.model.script.HVAC_CH_Off.rules] - CH AuTO mode checking...
2020-01-16 12:37:50.161 [INFO ] [thome.model.script.HVAC_CH_Off.rules] - ...temperature=16 demand=15
2020-01-16 12:37:50.171 [INFO ] [thome.model.script.HVAC_CH_Off.rules] - ...using hysteresi, go ON  if temp < 14.5
2020-01-16 12:37:50.179 [INFO ] [thome.model.script.HVAC_CH_Off.rules] - ...using hysteresi, go OFF if temp > 15.5
2020-01-16 12:37:50.200 [INFO ] [smarthome.model.script.HVAC_CH.rules] - ...CH turned OFF by AUTO rule
[12:

On the 3 way switch I went to OFF then from OFF to AUTO

A rule sets i_HVAC_CH_Switch to OFF because in AUTO the actual temp is above the demand temp so turn off boiler which is correct. But the boiler is already OFF because I went from OFF to AUTO , so boiler was already OFF. The events.log shows “…to become OFF” but never forcibly goes to OFF . Could that be it?

I also have widgets only visible in AUTO mode and these correctly occult when Proxy item is ON or OFF, and are displayed correctly when in AUTO so i know the system has the correct Proxy value, and in the log file one can see the rule being activated and turning boiler of OFF , but the fire-on icon is displayed , which is incorrect.

Fire-off is correctly displayed when I move the Proxy item swtich to OFF.

Strange
??

visibility needs to be placed at the end

I didnt get any sitemap errors , even so I have changed to put visibility at end of lines, but, no difference
?

This could be just a visibility refresh issue. You cannot tell which of your two alternative lines you are looking at.
Change the label text for one temporarily, so you know which you have in view.