Automation/Orchestration Design Patterns

@rlkoshak Hi I was hoping you may be able to help me. I have openhab running with my phillips hue bridge. I was able to get all of my phillips hue lights working properly and one sylvania lightify socket/on/off switch with the Phillips Hue Bridge. I grouped all of my lights in Paper UI as “All Lights Switch” however since I had to manually add the socket item via SSH it wont allow me to add it to the “All Lights Switch” group via Paper UI. Can you help advise how to get it to work with the group? Below is the home.items file

//Groups
Group:Switch:OR(OFF,ON) gAll_lights_Switch “All Lights Switch”

//Light Switches
Switch Dining_Room “Dining Room” (gAll_lights_Switch) [ “Switchable” ] {channel=“hue:0010:0017882f1db1:7:switch”}

/* Fibaro Sensors */
Number FibEye01_Movement “FE01 Movement: [%s]” (gZWave) {channel="zwave:device:15ecf0f7$
Number FibEye01_Temp “FE01 Temperature: [%.1f °F]” (gZWave) {channel="zwave:device:15ecf0f7$
Number FibEye01_Lux “FE01 Lux: [%.2f Lux]” (gZWave) {channel="zwave:device:15ecf0f7$
Number FibEye01_Bat “FE01 Battery [%s %%]” (gZWave) {channel="zwave:device:15ecf0f7$
Number FibEye01_Alarm “FE01 Alarm: [%s]” (gZWave) {channel="zwave:device:15ecf0f7$

It isn’t clear but I think your problem is you are mixing PaperUI and .items files. Since you are defining your Items in a .items file, do everything through the .items file. This means, do not add the Items to your all lights group through PaperUI. Generally, PaperUI is not able to do much of anything with Items bound to 1.x version bindings.

Thank you I was able to solve the issue by creating a “All Lights” Rule in paper UI. Now when i click the all lights button in habpanel the socket switches turn off along with all of the phillips hue bulbs.

1 Like

@rlkoshak

Hi rich, is this example from you working in OH 2.2 too?

val Functions$Function4 applySwitch = [ State state,
                                        boolean override,
                                        String whoCalled,
                                        SwitchItem light |
    if(state != light.state) {
        if(!override) {
            logInfo("Lights", whoCalled + " turning " + light.name + " " + state.toString)
            sendCommand(light, state.toString)
        }
        else {
            logInfo("Lights", whoCalled + " " + light.name + " is overridden")
        }
    }
]

I’ve tried to translate it to OH2.2 but ‘State’ is the problem, Error (State cannot resolved to a type).Any idea?

val Functions$Function4<State, Boolean, String, SwitchItem, Boolean> applySwitch = [state, override,  whoCalled,  light |
    if(state != light.state)
    {
        if(!override)
        {
            logInfo("Lights", whoCalled + " turning " + light.name + " " + state.toString)
            sendCommand(light, state.toString)
        }
        else
        {
            logInfo("Lights", whoCalled + " " + light.name + " is overridden")
        }
    }
    true
]

thats 5 input parameters, shouldn’t it be 4? I am not on OH2.2 but

val Functions$Function4 applySwitch = [ State state,
                                        boolean override,
                                        String whoCalled,
                                        SwitchItem light

works fine with oh1.1

@skatun
No this is correct, the last one is the return because it is a function not a procedure. And in OH 2.2 this is needed.

Found it,

import org.eclipse.smarthome.core.types.State

FWIW, you can still use the old syntax in latest OH. It’s throwing warnings but it’s working.

1 Like

That is surprising. I was under the impression that everything from org.eclipse.smarthome.core.types was imported by default.

Do you see the error when you run or just in VSCode/ESH Designer?

Since light is a SwitchItem, you can and should use the more specific OnOffType instead of State anyway. That should work without the import.

Hi Rich,

I have not tested it, just got the error in VC and tried to fix it here.

Maybe is will work without this line. I will try it tomorrow, but I like it to have no errors in VC code. Makes it more readable

I am getting following error when using Time of Day Design Pattern rule,

2018-07-19 05:15:44.924 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'timeofday.rules'
2018-07-19 05:15:46.089 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'timeofday.rules', using it anyway:
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
The use of wildcard imports is deprecated.
Function3 is a raw type. References to generic type Function3<P1, P2, P3, Result> should be parameterized
The method getCalendar() from the type DateTimeType is deprecated
The method getCalendar() from the type DateTimeType is deprecated
The method getCalendar() from the type DateTimeType is deprecated
2018-07-19 05:15:46.093 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'timeofday.rules'
2018-07-19 05:15:51.214 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Get time period for right now': Could not cast NULL to org.eclipse.smarthome.core.library.types.DateTimeType; line 22, column 37, length 34

Any idea what is the issue?

Please see Design Pattern: Time Of Day