Switch MQTT-channel: multiple states for ON/OFF

I’m using openHABian 1.9 with openHAB 4.1.1.

I’m receiving the states of docker containers via MQTT and want to convert them to ON/OFF in a switch:

  • ON:
    ** running

  • OFF:
    ** stopped
    ** exited

so, is there a way to either define multiple “off”-states or accept wildcards/regex?

UID: mqtt:topic:synology:homeserver
label: MQTT Homeserver
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:synology
channels:
  - id: mosquitto_online
    channelTypeUID: mqtt:switch
    label: Mosquitto MQTT server online
    description: ist der Container online
    configuration:
      stateTopic: servers/Homeserver/dockercontainer
      transformationPattern: JSONPATH:$.['eclipse-mosquitto:latest'].state
      off: exited
      on: running

Chain it with MAP transformation

Maybe with a Map Transformation?
I have this in one MQTT-Item, I created a .map-file in the transform directory and defined it as Incoming value transformation: MAP:myfile.map

The content of the file looks like this:

running=ON
stopped=OFF

1 Like

Thanks!
this works

  - id: mosquitto_online
    channelTypeUID: mqtt:switch
    label: Mosquitto MQTT server online
    description: ist der Container online
    configuration:
      stateTopic: servers/Homeserver/dockercontainer
      transformationPattern: JSONPATH:$.['eclipse-mosquitto:latest'].state∩MAP:dockerStates.map

dockerStates.map:

running=ON
stopped=OFF
exited=OFF
paused=OFF