[SOLVED] Multiple Things in a Single File - Can this be done?

(Mike Miller) #1

Newly migrated from OH1 to OH2 and still working out all the differences. Question I came across - is it not OK/Possible/Proper to have multiple Things in a single file like so?

exec.things

Thing exec:command:outlet-power [ 
           command="/home/pi/python_scripts/automation/v2/codesend %2$s",
           interval=0,
           autorun=true]

Thing exec:command:zigbee-bulb-power [ 
           command="/home/pi/oh_custom_scripts/wink-as-pi.sh %2$s",
           interval=0,
           autorun=true]

I have 2 separate items files for the 2 different commands:

zigbee_bulbs.items

Switch zigbee_bulb_Lydias_lamp <lightbulb>
Switch zigbee_bulb_desk_lamp   <lightbulb>

Switch Outlet_Power         { channel="exec:command:zigbee-bulb-power:run"       }
String Outlet_Power_Args    { channel="exec:command:zigbee-bulb-power:input"     }
String Outlet_Power_Out     { channel="exec:command:zigbee-bulb-power:output"    }

And rf_outlets.items

Switch rf_plug_LR_lamp <poweroutlet>

Switch Outlet_Power         { channel="exec:command:outlet-power:run"       }
String Outlet_Power_Args    { channel="exec:command:outlet-power:input"     }
String Outlet_Power_Out     { channel="exec:command:outlet-power:output"    }

rf_outlets.rules (will be changing the name of this to something that makes more sense later)

rule "Living Room Lamp"
    when
        Item rf_plug_LR_lamp received command
    then
        // wait for transmitter to be free
        // state will be NULL if not used before or ON while command is executed
        while(Outlet_Power.state == ON){
            Thread::sleep(500)
        }

        if(receivedCommand == ON){
            Outlet_Power_Args.sendCommand("5330371")
        } else {
            Outlet_Power_Args.sendCommand("5330380")
        }

        // wait for the command to complete
        while(Outlet_Power.state != OFF){
            Thread::sleep(500)
        }

        logInfo("RF Outlets","Result:" + Outlet_Power_Out.state)
end

rule "Lydias Lamp"
    when
        Item zigbee_bulb_Lydias_lamp received command
    then
        // wait for transmitter to be free
        // state will be NULL if not used before or ON while command is executed
        while(Outlet_Power.state == ON){
            Thread::sleep(500)
        }

        if(receivedCommand == ON){
            Outlet_Power_Args.sendCommand("-m 1 -u -t 1 -v ON")
        } else {
            Outlet_Power_Args.sendCommand("-m 1 -u -t 1 -v OFF")
        }

        // wait for the command to complete
        while(Outlet_Power.state != OFF){
            Thread::sleep(500)
        }

        logInfo("Zigbee Bulbs Lydias Lamp","Result:" + Outlet_Power_Out.state)
end

rule "Desk Lamp"
    when
        Item zigbee_bulb_desk_lamp received command
    then
        // wait for transmitter to be free
        // state will be NULL if not used before or ON while command is executed
        while(Outlet_Power.state == ON){
            Thread::sleep(500)
        }

        if(receivedCommand == ON){
            Outlet_Power_Args.sendCommand("-m 9 -u -t 1 -v ON")
        } else {
            Outlet_Power_Args.sendCommand("-m 9 -u -t 1 -v OFF")
        }

        // wait for the command to complete
        while(Outlet_Power.state != OFF){
            Thread::sleep(500)
        }

        logInfo("Zigbee Bulb Desk Lamp","Result:" + Outlet_Power_Out.state)
end

Essentially, when I flip the switch, BOTH of the commands in the Things file fire with the parameters of the specific item that was invoked. So, I get a successful action and the other one, of course fails with errors. This happens both ways and I am not sure where the issue is. The logs are quite long so I won’t post them here, so hopefully what I am saying makes sense.

0 Likes

(Vincent Regaud) #2

The items in zigbee_bulbs.items and rf_outlets.items have the same same!

You will get errors and possibly duplicated calls to items which seems to be the case.

Change the names in the files. eg.

zigbee_bulbs.items

Switch zigbee_bulb_Lydias_lamp &lt;lightbulb&gt;
Switch zigbee_bulb_desk_lamp   &lt;lightbulb&gt;

Switch Outlet_Power_Z         { channel="exec:command:zigbee-bulb-power:run"       }
String Outlet_Power_Z_Args    { channel="exec:command:zigbee-bulb-power:input"     }
String Outlet_Power_Z_Out     { channel="exec:command:zigbee-bulb-power:output"    }

And rf_outlets.items

Switch rf_plug_LR_lamp &lt;poweroutlet&gt;

Switch Outlet_Power_RF         { channel="exec:command:outlet-power:run"       }
String Outlet_Power_RF_Args    { channel="exec:command:outlet-power:input"     }
String Outlet_Power_RF_Out     { channel="exec:command:outlet-power:output"    }

and change your rf_outlets rules to use the _RF items only
and the zigbee bulbs rules to use the _Z items only

1 Like

(Josar) #3

As already mentioned you can put all items in the same file. But no matter if in separated files or not each name has to be unique items, rules, sitemaps and things.

For multiple RF devices in one rule use the last example with the led stripes, from my post. Key points reentrance lock. Implicit variables. Group trigger which I have to add as it just got available.

rule "test"
when
Member of GroupRFdevices received command
then

Do you use VSCode with the openhab extension?
It’s great and helps solve problems.

And my personal setup :wink:

2 Likes

(Mike Miller) #4

Thanks to both of you. My misunderstanding was that I thought only the command needed to be a different name that that the other part could be the same. I will fix that and I assume my problem will go away.

You already answered the question regarding being able to put them in the same item file, though I may still keep them separate for a more modular approach.

Actually, I do use this, but I don’t think my extension is working properly. It does sort of offer some auto-fill intellisense, but not seeing anything related errors or anything like that. I will have to check that out to find out what may be going on with it.

Thanks again!

0 Likes