Issue to add first sonoff / mqtt -switch in a sitemap

Hello,
I just try to add my first sonoff into a sitemap, from shell the connection and receiving mqtt is fine.
On the shell I get the following answer when pressing the physical button on the sonoff:

stat/sonoff/sonoff-switch-02/RESULT {“POWER”:“OFF”}
stat/sonoff/sonoff-switch-02/POWER OFF
stat/sonoff/sonoff-switch-02/RESULT {“POWER”:“ON”}
stat/sonoff/sonoff-switch-02/POWER ON

In my Items-file I add:

    Switch Switch_TV_Simulation
      "TV Simulator"
      [ "Switchable" ]
      {mqtt=">[broker:cmnd/sonoff/sonoff-switch-02/POWER:command:*:default], <[broker:cmnd/sonoff/sonoff-
    switch-02/POWER:state:default]" }

And in the sitemap I simple add:

 Switch item=Switch_TV_Simulation label="TV Simulation"

Now I see the switch-button in the sitemap, but nothing happens (nothing when pressing the physical button, niting when pressing the button in oH).

In the log from Visual Studio I get: “Received HTTP POST request at ‘items/Switch_TV_Simulation’ for the unknown item ‘Switch_TV_Simulation’.”

Actuall I don’t understand … shurly a"simple" mistake/missunderstanding on my side …

Which binding did you install? mqttv1 or mqttv2?
So you have a MQTT Broker installed and running?

In PaperUI I see: binding-mqtt1 - 1.12.0

Yes, it’s running, I allready use mqtt to get the energy (water & electricity) consumption signals (they are sendet by shell script from another Raspberry, and this works).
So I think it’s a syntax or logical error on my side (2 month ago I add my last item :wink: )

Hi, try it this way:

Switch    Sonoff_socket_01 "Wohnzimmer LED 1 [MAP(de.map):%s]"  <lamp_globe_light>      (EG_Wohnen,gPlugSwitch,gSonoff)  { mqtt=">[yourbroker:cmnd/schaltdose01/power:command:*:default],
                                                                                                                                 <[yourbroker:stat/schaltdose01/POWER:state:default]" }

I saw my (first?) mistake,
I used: {mqtt=">[broker:cmnd/sonoff/…
But I think (saw in log and in other mqtt item) I have to user: {mqtt=">[**mosquitto:stat/**sonoff/…

In log I see:

_Could not update element with key tags:Switch_TV_Simulation in ManagedMetadataProviderImpl, because it does not exists.

And when controlling mqtt I see the mqtt was send (+) when pusing the button in oH, but the sonoff did not switch :frowning:
(+) stat/sonoff/sonoff-switch-02/POWER OFF
stat/sonoff/sonoff-switch-02/POWER ON

if mosquitto is the name of your broker, that’s correct. This is the name you gave it in your mqtt.cfg

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
yourbroker.url=tcp://localhost:1883

The angle should look to the left for the stat-command, like this <

and of course delete the metadata [ “Switchable” ] for testing. I think there is another problem too.

To send a command for turning on the switch use cmnd not stat

You item should look like this:

Switch Switch_TV_Simulation "TV Simulator" ["Lighting"]
      { mqtt=">[broker:cmnd/sonoff/sonoff-switch-02/POWER:command:*:default], <[broker:stat/sonoff/sonoff-switch-02/POWER:state:default]" }

Just make sure to use the correct broker name as @fibu-freak mentioned above.

Example if the broker name is mosquitto the item should look like this:

Switch Switch_TV_Simulation "TV Simulator" ["Lighting"]
      { mqtt=">[mosquitto:cmnd/sonoff/sonoff-switch-02/POWER:command:*:default], <[mosquitto:stat/sonoff/sonoff-switch-02/POWER:state:default]" }

that’s it, as @H102 described. The first mqtt-command sends the command (cmnd) to switch on or off, and the second command (stat) receives if update was done.
BTW for what purposes you need the metadata ?

1 Like

Thanks H102, now it works , somewhere I found (or saw) this example with two “stat’s” and use it …

Peter, what do you mean with “or what purposes you need the metadata ?” ?

Glad you have it working.:+1:

The tags in the items e.g. [ “Lighting” ]. They are used to allow voice control with devices like Alexa. If you have no need for this you can remove the tag.

If your topic is solved, please mark it as so by clicking the square box (lower right corner) on the post that provided the solution and edit the title to start with [Solved]. This will help other with a similar issue find a quick solution.

Thanks