How to create a multiselection to use in rules

Hi There,

does anyone out there has an idea how to create a multi selection in the sitemap. Inmy mind i have currently something linke check marks and from these are values generated.

I need this for my notification rule. Any participant should habe the option to set the level of information he/she will get. I defined following levels: Info, Action, Warning, Alert

The user should be able to select which of the he/she will receive.

Any ideas?

Thomas

e.g.
Switch item=Szene icon=“color” label=“Szene” mappings=[1=“morgens”, 2=“tags”, 3=“abends”, 4=“Nacht”, 100=“TV”, 0=“Aus”]

The item can be defined in items file to be of Number or String type

Not that way. I would like to select “morgens” und “abends” or “abends” and “tag” or all three. so with any combination it is complicated.

Thomas

That’s not what you asked for. Use multiple switch items then, one per level?
Also, for notifications, it doesn’t make sense to select e.g. ‘Action’ and ‘Alert’ only (and deselect ‘Warning’) because if you select ‘Action’ level logging, you (commonly) want to see all higher level messages, including ‘Warning’ (i.e. Action, Warning, Alert).

Thats your idea. For me warning are interesting for my wife not, but she is interested in Alerts and Action messages. To create switches is a huge effort if i have more recipients that should receive different messages

Thomas

one line per switch is huge effort?

I’m afraid you will need to use switches. Any special logic (e.g. if you select Alert you can’t select Warning) will be implemented in rules.

You can make the “huge effort” easier by using groups.

Items:

// Group and switches which control who gets what notifications
Group gNotificationSettings
Switch Me_Info    (gNotificationSettings)
Switch Me_Action  (gNotificationSettings)
Switch Me_Warning (gNotificationSettings)
Switch Me_Alert   (gNotificationSettings)

Switch Wife_Info    (gNotificationSettings)
Switch Wife_Action  (gNotificationSettings)
Switch Wife_Warning (gNotificationSettings)
Switch Wife_Alert   (gNotificationSettings)

// Items which act as proxies for alerts that get sent
String Info
String Action
String Warning
String Alert

// Items which act as a proxy for sending an alert to indicated people
String NotifyMe
String NotifyWife

Rules:

import org.eclipse.xtext.xbase.lib.*
import org.openhab.core.items.*
import org.openhab.core.library.items.*

val Functions$Function3 send = [ String level, String message, GroupItem params |
   val flags = params.members.filter[s|s.name.endsWith(level)]
   flags.forEach[ s |
        if(s.state == ON) {
            val who = s.name.split("_").get(0)
            sendCommand("Notify"+who, Info.state.toString)
        }
    ]
]

rule "Notify Me"
when
    Item NotifyMe received command
then
    // code to send NotifyMe.state.toString to Me
end

rule "Nofity Wife"
when
    Item NotifyWife received command
then
    // code to send NotifyWife.state.toString to Wife
end

rule "Info"
when
    Item Info received command
then
    send.apply("Info", Info.state.toString, gNotificationSettings)
end

rule "Action"
when
    Item Info received command
then
    send.apply("Action", Info.state.toString, gNotificationSettings)
end

rule "Warning"
when
    Item Info received command
then
    send.apply("Warning", Info.state.toString, gNotificationSettings)
end

rule "Alert"
when
    Item Info received command
then
    send.apply("Alert", Info.state.toString, gNotificationSettings)
end


// Example: To send an Info message Info.sendCommand("message")

Theory of operation:

To send a notification sendCommand the message to one of the alerts proxy String Items (e.g. Info).

This causes a rule to trigger which calls a lambda called send.

This lambda is where the magic happens. It filters gNotificationSettings to get all Items that end in the logging level (e.g. the Info rule passes “Info” as the logging level so the result of the filter will be those two switches which end in “Info”. It then loops through all of those and extracts the first part of the Switch’s name. This is then used to construct the name of the Notification proxy Item associated with that person (e.g. NotifyMe) and the message is sendCommand to that Item. This triggers the Notify rule which actually implements the code to pass the message on to you.

To add a new person you just need to create new Name_Info et al Items and make them part of the gNotificaitonsSettings group.

NOTES:

  • I just typed this in, there may be errors.