Trouble creating an item that display value of Sonoff in sitemap

Hello, I’m having issues with getting the input from MQTT to my sitemap, it works all fine when i use console commands like:

    mosquitto_sub -d -t /zzzz/relay/relay
    mosquitto_pub -t /zzzz/relay/relay/gpio/12 -m 1

This all works fine, but when I do

Contact zzzz { mqtt="<[broker:/zzzz/relay/relay:command:ON:1]" }

in my items file and then add

Text item=zzzz

to my sitemap it doesn’t display the value

Try this:

Contact zzzz "zzzz [%s]" { mqtt="<[broker:/zzzz/relay/relay:command:ON:1]" }

or

Text item=zzzz label="zzzz [%s]"
1 Like

Now I can see “zzzz {-}” instead of "zzzz {blank}"
Didn’t help, could it be the mqtt.conf file?
Here is a copy of it

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#
# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
broker.url=tcp://1.1.1.67:1883
# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#broker.clientId=OPENHAB2
# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false
# Optional. User id to authenticate with the broker.
broker.url.user=openhabian
# Optional. Password to authenticate with the broker.
broker.url.pwd=adminas12
# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>
# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#mqtt:broker.retain=true
# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#mqtt:broker.async=false
# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

P.S I’m available to see the values in MQTT.fx

are you sure your broker ip is 1.1.1.67?. if it’s localhost, type:

broker.url=tcp://localhost:1883
1 Like

Didn’t help

Is your broker installed on the same machine as OH?

1 Like

Yes

Is the broker setup for accepting the credentials username and password?
check the logs via

ssh -p 8101 openhab@localhost
log:tail

to see if OH connects to the broker
Also, try changing mqtt.cfg if credentials are set correct in the broker:

broker.user=openhabian
broker.pwd=adminas12
1 Like

I’m trying it right now

I tried passwords adminas12 [ my user password ] and openhabian

The authenticity of host '[localhost]:8101 ([127.0.0.1]:8101)' can't be established.
RSA key fingerprint is 11:37:74:65:b9:8d:3f:90:c5:94:fe:e9:95:3d:e8:2a.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '[localhost]:8101' (RSA) to the list of known hosts.
Password authentication
Password:
Password authentication
Password:
Password authentication
Password:
openhabian@localhost's password:
Permission denied, please try again.
openhabian@localhost's password:
Permission denied, please try again.
openhabian@localhost's password:

This is what i get

16:08:38.823 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker '<broker>'
16:08:48.829 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'
16:08:49.933 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
Connection lost (32109) - java.io.EOFException
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)[208:org.openhab.io.transport.mqtt:1.10.0]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
Caused by: java.io.EOFException
        at java.io.DataInputStream.readByte(DataInputStream.java:267)[:1.8.0_121]
        at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)[208:org.openhab.io.transport.mqtt:1.10.0]
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)[208:org.openhab.io.transport.mqtt:1.10.0]
        ... 1 more
16:08:49.942 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to '<broker>' was lost: Connection lost : ReasonCode 32109 : Cause : null

I think you are missing the point. The broker credentials has nothing to do with the ssh connection to the karaf console. The karaf console connection at openhab@localhost has the default password habopen
Take a look here
And also take a look here.
So, please read these documents first.

1 Like

Now I’m getting

16:13:54.059 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker '<broker>'
16:14:04.061 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'
16:14:05.109 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
Connection lost (32109) - java.io.EOFException
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)[208:org.openhab.io.transport.mqtt:1.10.0]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
Caused by: java.io.EOFException
        at java.io.DataInputStream.readByte(DataInputStream.java:267)[:1.8.0_121]
        at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)[208:org.openhab.io.transport.mqtt:1.10.0]
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)[208:org.openhab.io.transport.mqtt:1.10.0]
        ... 1 more
16:14:05.115 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to '<broker>' was lost: Connection lost : ReasonCode 32109 : Cause : null

Take a look here:

2 Likes

SOLVED IT
Thank you for your help

The issue was that I set a password while installing Mosquitto from

sudo openhabian-config

I left it blank and it worked, also I’m using a value of 1 and 0 so I needed to do

String zzzz "zzzz [%s]" { mqtt="<[broker:/zzzz/mygtukas/Switch:state:default]" }

Instead of

Contact zzzz "zzzz [%s]" { mqtt="<[broker:/zzzz/mygtukas/Switch:state:default]" }

Thank You for your help, couldn’t solve it without you. :slight_smile:

1 Like