Choosing the correct transformation

Hi,

In my setup I use quite some *.map files to simply map ON/OFF status of all my lights.
I have one for every light since the value has a unique ID in it.
Isn’t there an option to work with 1 transformation and a kind of mapping file that maps my light to the correct id? (either flat or in xml format

kitchenlight=01
roomlight=02

<Lights>
   <Light name="kitchenlight" id="01"/>
   <Light name="roomlight" id="02"/>
</Lights>

I guess I’ll need to use a javascript transform or something. But I don’t know how to pass on the ON/OFF and the name of my light to a js function

Kind Regards
Tim

Hello Tim,
I’m confused about what your are trying to achieve. How are your lights integrated (which binding) and what’s the origin of the source code you’ve posted?

Sorry, my mind can be a confusing place sometimes. :slight_smile:
My lights are integrated through the UDP binding. I need to send specific commands for ON and OFF with a unique ID for the light I wast to control.

It’s not really an existing piece of code. But more like how I imagine my mapping file could look like.
With mapping file, I just mean a simple way to map the unique name of my light to the unique ID in my relay module.
Could be either an XML or plain text file.

So what I’m trying to accomplish here is that I have my items file, a js transformation file and my custom mapping file.
When I switch a light, I want to go to the js file that determines the correct ID based on the name of the light that I switched.

That would eliminate the 20 *.map files that I have and I can just program the logic.

Would it be an option to use rules for all of that? Here’s one simple rule I use to do something similar:

rule "Sound System: Switch between PC input and Sonos input channel"
when
    Item KodiPlayerState changed
then
    //logInfo(filename, "Sound System: Switch between PC input and Sonos input channel")
    if (KodiPlayerState.state == "Play") WZ_zMote_sendcode.sendCommand("38000,2,69,343,171,21,22,21,65BBBBBBBBBBBCBCBBCBBBBBCCBCCCCC21,1672,343,86,21,3730")
    else if (KodiPlayerState.state == "Stop") WZ_zMote_sendcode.sendCommand("38000,2,69,343,171,21,22,21,65BBBBBBBBBBBCBCBCBBBBBCCBCCCCCB21,1672,343,86,21,3730")
end

Would you see it as 1 rule per light? Or 1 rule that acts on all the lights?
As a developer I would like 1 event trigger to process all, but then I would need some kind of context properties to determine which light I want to turn on.

Depends on your setup and the count of your lamps. You said you have around 20 lamps, so I guess you want to use one rule only. That’s possible. You’ll find out how to do so in the Design Patterns article series, probably this one: Design Pattern: Working with Groups in Rules
For a similar use case I have indeed just 20 copy-pasted (simple) rules. You need to decide :wink:

I’ll have a try when I have some extra time.