Send command with .map with MQTT

Hi, can I send command (with MQTT) on a topic using a .map file?
I work with habpanel

This is good configuration

String SL_INGRESSO_1 (SL_INGRESSO) {mqtt=">[pibroker:SL_INGRESSO:command:*:default]"}
Switch ACCENDI_SL_INGRESSO "LED RGB ON" {mqtt=">[pibroker:SL_INGRESSO:command:ON:100;100;100]",autoupdate="false"}
Switch SPEGNI_SL_INGRESSO "LED RGB OFF" {mqtt=">[pibroker:SL_INGRESSO:command:ON:0;0;0]",autoupdate="false"}

My idea is

String SL_INGRESSO_1 (SL_INGRESSO) {mqtt=">[pibroker:SL_INGRESSO:command:*:default]"}
Switch ACCENDI_SL_INGRESSO "LED RGB ON" {mqtt=">[pibroker:SL_INGRESSO:command:ON:MAP(]",autoupdate="false"}
Switch SPEGNI_SL_INGRESSO "LED RGB OFF" {mqtt=">[pibroker:SL_INGRESSO:command:OFF:MAP(]",autoupdate="false"}



Can someone help me, please? Thanks

PS: I use rules too, if someone need them, I will post the code

you have to use a string item when mapping to a string (just a guess).

It should work with the MAP but it may not like the semicolons. In a typical .ini file a semicolon is a comment character.

Try escaping the semicolons with \;

Hi, sorry for my late response.

Now, I use another strategy because it’s very simple (but very ugly): when I’ve got some free time, I will test with MAP.

Thank @rlkoshak and @Udo_Hartmann for the help


For the future readers of this forum, care to post your simple solution? Beauty is in the eye of the beholder. :wink:

1 Like

Hi, I’m going to post my solution

This is my .item configuration, I’ve got 17 item like this

	String SL_OPENSPACE_AUTO {mqtt=">[pibroker:SL_OPENSPACE:command:ON:67;78;100]",autoupdate="false"}
	String SL_OPENSPACE_1 (SL_OPENSPACE_1) {mqtt=">[pibroker:SL_OPENSPACE:command:*:default]"}
	Switch ACCENDI_SL_OPENSPACE "LED RGB ON" {mqtt=">[pibroker:SL_OPENSPACE:command:ON:100;100;100]",autoupdate="false"}
	Switch SPEGNI_SL_OPENSPACE "LED RGB OFF" {mqtt=">[pibroker:SL_OPENSPACE:command:ON:0;0;0]",autoupdate="false"}

No sitemap because I implement habpanel

Rule to do a carcadian cycle ( to change RGBW leds color during a work day to help human

rule "ciclo"
		Item auto received update
		while (conta == 0) {
			if(auto.state == ON){
				var Number hour = now.getHourOfDay
				if ((hour >= 9)  && (hour < 11)) {
					sendCommand( SL_INGRESSO_1, "67;78;100")
					sendCommand( SL_OPENSPACE_1, "67;78;100")
					sendCommand( SL_UFFICIO_2_1, "67;78;100")
					sendCommand( SL_UFFICIO_3_1, "67;78;100")
					sendCommand( SL_UFFICIO_4_1, "67;78;100")
					sendCommand( SL_SALA_RIUNIONI_1, "67;78;100")
					sendCommand( SL_SEGRETERIA_1, "67;78;100")
					sendCommand( SL_CORRIDOIO_1, "67;78;100")
					sendCommand( SL_LOUNGE_1, "67;78;100")

This is my solution, hope this can help someone. If you think it isn’t the best solution, please tell me some hints to improve it.

Thanks for the support,

1 Like

A few comments on your rule code that have nothing to do with your original question but which might improve it or your OH’s overall performance. These are not intended to be critiques, just suggestions.

  • You can trigger the rule on Item auto received command ON and drop the if(auto.state == ON) in the rule. You really should trigger something like this with a command instead of an update for logical consistency.

  • What is conta? I assume it is a global variable but there is no clue as to when or how it gets set in this code.

  • Thread::sleep longer than 300 msec are strongly discouraged. A better approach is to use Timers.

  • I don’t understand why this code is in a loop at all. All of the Lights are set to the same color value each time through the loop. What is driving the loop? Is there some other way you can trigger a rule based on an event to reset the light’s color instead of looping?

  • If you have any other rules that care about time of day I recommend adopting the Time of Day DP.

  • It is usually better practice to use the sendCommand methods instead of the sendCommand Actions. For example:


  • Since you set the lights all to the same color, you should define the color as a val so if you decide to tweak the color later you can do so in only one place.

  • Since you set the lights all to the same color, you should add them all to a Group:Color Lights and send the command to the Group. The command will be forwarded to all the members of the Group.

Given the comments above, your Rule could look something like the following (note, I don’t know enough details to implement the removal of the loop so below implements something equivalent). This uses the Time of Day DP and Expire Based Timers DP.

New Items

    Group:Color Lights
    Switch Ciclo_Timer { expire="1m,command=OFF" }
    Number conta

NOTE: I’ve moved conta to an Item instead of a global var, still don’t know what it does or how it gets populated

val dayColor = "67;78;100"

rule "ciclo"
    Item auto received command ON
    if(vTimeOfDay.state == "DAY") {

rule "ciclo Timer"
    Item Ciclo_Timer received command OFF
    if(auto.state == ON && conta.state as Number == 0 && vTimeOfDay.state == "DAY") {

rule "conta"
    Item conta changed
    if(conta.state as Number != 0) Ciclo_Timer.postUpdate(OFF)