Having Trouble configuring Items

Hi,
I`m experiencing problem with the items file. I just cant get it to turn on and off the relay. Here is what I have writen in the file:
Switch Livingroom_light “Livingroom Light” {mqtt=<[broker:House/Livingroom/Light:command:ON:ON],>[broker:House/Livingroom/Light:command:OFF:OFF]" }

Everything else is configured fine, when i type the command manualy i can triger the ralay but i cant do nothing from openhab.
I`ve also configured a test sitemap file and i get the switch on the screen but it does noting.

See this examples

Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:/ESP/LED/001:command:on:1],
                                       >[mosquitto:/ESP/LED/001:command:off:0],#
                                       <[mosquitto:/ESP/LED/001:state:default]"}
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:testsw/1:command:*:default],
                                       <[mosquitto:testsw/1:state:default]"}

I still dont get it mqttsw1 shoud be the topic or just an item name? The other problem is that my relay always turns on when i start the esp and the ON/OFF commands are reversed when i test it manualy and through openhab it still doesent work.

Well i fixed the reversed ON/OFF functions, but i still can make the switch ion my openhab interface to work.
Here is the contents of the items file:
Switch House/Livingroom/Light “Switch 1” (all) {mqtt=">[mosquitto:/House/Livingroom/Light:command:OFF:0], >[mosquitto:/House/Livingroom/Light:command:ON:1],#<[mosquittsquitto:/House/Livingroom/Light:state:default]"}

And the sitemap file:
sitemap home label=“LYNX Smart Home”
{
Frame label=“Light”
{
Switch item=House/Livingroom/Light
}
}

I wouldn’t use “/” in a item-name

Switch House_Livingroom_Light "Switch 1" (all) {mqtt=">[mosquitto:/House/Livingroom/Light:command:OFF:0],
                                                      >[mosquitto:/House/Livingroom/Light:command:ON:1],
                                                      <[mosquittsquitto:/House/Livingroom/Light:state:default]"}

Thanks for the advice! But still it wont work. Mqtt is configured properly if i subscribe using mqtt.fx and send commands it works. The sitemap i corect i think, but i`m having no luck geting the switch to work.

I`m having no luck with this thing if somebody can help me with this mistery?
This is the items file
Switch House_Livingroom_Light “Switch 1” (all) {mqtt=">[mosquitto:House/Livingroom/Light:command:OFF:OFF], >[mosquitto:House/Livingroom/Light:command:ON:ON], <[mosquitosquitosquittsquitto:House/Livingroom/Light:state:default]"}

This is the sitemap:

sitemap home label=“LYNX Smart House”
{
Frame label=“Demo”
{
Switch item=House_Livingroom_Light
}
}

In your first post, you used “brojer” as the name of your Matt broker, in all following post you copied the name “mosquitto”. Which name did you a sign to your Matt broker in the first place?

Im new to openhab and im not quite shure where to asign a name to the broker. I saw in mqtt-eventbus.cfg that it says MQTT. Is there another config file i need to edit? Where is it located?

services/mqtt.cfg
https://docs.openhab.org/addons/bindings/mqtt1/readme.html#transport-configuration

So i should edit the clientid?

My mqtt is configured and working fine when i send a command from MQTT.fx it works. It doesent want to work from Openhab.

Post you mqtt.cfg und a valid command you use from MQTT.fx please.

Define your MQTT broker connections here for use in the MQTT Binding or MQTT

Persistence bundles. Replace with an ID you choose.

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

.url=tcp://localhost:1883

Optional. Client id (max 23 chars) to use when connecting to the broker.

If not provided a random default is generated.

#.clientId=openhab

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.

#.allowLongerClientIds=false

Optional. User id to authenticate with the broker.

#.user=esp

Optional. Password to authenticate with the broker.

#.pwd=8266

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.

#.qos=

Optional. True or false. Defines if the broker should retain the messages sent to

it. Defaults to false.

.retain=true

Optional. True or false. Defines if messages are published asynchronously or

synchronously. Defaults to true.

.async=false

Optional. Defines the last will and testament that is sent when this client goes offline

Format: topic:message:qos:retained

#.lwt=

I ve commented off the user and the password on purpose because im not using them. From Mqtt fx i connect to the server, i subscirbe, then from the publish tab: House/Livingroom/Light and in the message box i type ON and OFF which successfuly trigers the relay. the file does not show up well before every line there should be

For better readable code please use the code fences

#
# 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://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=openhab

# 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>.user=esp

# Optional. Password to authenticate with the broker.
#<broker>.pwd=8266

# 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.
<broker>.retain=true

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
<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>

Replace < broker > with broker, mqtt, mosquitto or what you want und use this term in you item.

2 Likes

Thank you very much for the help! I apreciate it very very much!