Send string variable to MQTT

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

I am using the spotify integration and I want to send the name of the artist to MQTT.
Spotify integration puts the name into this item
String spotify_current_artist

I have created a MQTT item
String mqtt_spotify_current_artist “Artist” { mqtt=">[broker:Spotify/artist:command:*:default]"}

In a rule I manage to send to MQTT if use text:

but I have never been sucessfull to send the variabel spotify_current_artist to MQTT in a rule
mqtt_spotify_current_artist.sendCommand(spotify_current_artist.state as string)

How shall the line in the rule be formulated that send the variable spotify_current_artist to MQTT?


Works perfectly! Thanks