rule "send audio status zone 1"
when
Item zone1_vol changed or
Item zone1_bal changed or
Item zone1_high changed or
Item zone1_low changed or
Item zone1_source changed or
Item zone1_mute changed
then
if(zone1_mute.state == ON){
val String mute = "0"
}
if(zone1_mute.state == OFF){
val String mute = "1"
}
Audio_status_send.sendCommand("status zone 1," + zone1_vol_calc.state.toString + "," + zone1_bal.state.toString + "," + zone1_high.state.toString + "," + zone1_low.state.toString + "," + zone1_source.state.toString + "," + mute + ";")
end
The item “Audio_status_send” is a String item that sends it state to MQTT.
This is not working because the variable “mute” in the “Audio_status_send.sendCommand” command. When i delete the variable “mute” in this command than it is working.
So 2 things could cause my problem:
variable is wrong declared
variable need some extra information in the command “Audio_status_send.sendCommand”
You declared the val inside he if ( inside { }, that way it isn’the known outside.
You use a val (value, cannot be changed).
Use a var declared above the if.
thanks, I was forgotten that the val value was a fixed value. i thougth that is was no problem because is change only when the rule is activated and the variable was created inside the rule (and placed is on the wrong place)
I was referring to the error only.
Regarding the used “sendCommand”: It looks like the items which is receiving this command is used to be persisted only, in this case a “postUpdate” should be mor appropriate.
Why are persisting such a combination string instead of seperated values or strings for each item?
I use the sendcommand because the string has to pushed to the MQTT binding. I understood that postupdate was only updated the value and that you need to use sendcommand to push it to the binding for that particular item.
But for my question i want to know or the structure behind the command is OK, I mend this part:
I allready did that (before the remarks of OPUS) and I get nothing.
I is like the rule is not fully executed. First I going to implement the remarks of OPUS and see what is happening.
This is the zone status for a multiroom audio system. The string is send with MQTT to a ESP-12e WiFi device that put this string directly on it’s serial port to the multiroom audio system.
So everytime that a parameter of a zone in openhab is changing a want to send the zone status to the multiroom audio device.
I’m not verry good at programming so maybe this is not the best way to implement this things but it is working (except for the mute variable, I have to covert the ON and OFF status of the switch item to a 0 and 1 value for the audio device.