MQTT connectivity help

I can’t write to my Mosquitto MQTT Broker running on my Rpi from openhab also running on my Rpi.
I can pub/sub from command line and from Windows PC runnign mqtt.fx to this broker, but just not from openhab.
(I am pretty new to all this and brand new to mqtt).

I currently have a working ecobee thermostat temperature in openhab with item:
Number DiningRoomTemp "Dining Room Temp [%.1f °F]" <temperature> (jt) { ecobee="<[123456789012#remoteSensors(Dining Room).capability(temperature).value]" }

I would like to relay this temperature to MQTT for use elsewhere.

I first tried creating an MQTT item:
Number MQTToutDiningRoomTemp "MQTTout Dining Room Temp [%.1f °F]" <temperature> (jt,jtmqtt) { mqtt=">[rpiopenhabbroker:house/dining/temperature:state:default]" }
and then a rule to write to it my mqtt.rules:
* This is a multi-line
* comment

// This is a single line comment or a end of line (trailing) comment

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*

// Global Variables

rule "My MQTT Rules: Relay Diningroom Temp to MQTT"
	Item DiningRoomTemp changed
	logInfo("INFO","DiningRoomTemp changed, relay to MQTT.")
	var tempDiningRoomTemp = (DiningRoomTemp.state as DecimalType).doubleValue
	postUpdate(MQTToutDiningRoomTemp, tempDiningRoomTemp)
//	sendCommand(MQTToutDiningRoomTemp, tempDiningRoomTemp)
//	publish("rpiopenhabbroker","house/dining/temperature",DiningRoomTemp.state)
	logInfo("INFO","My MQTT Rules: Relay Diningroom Temp to MQTT completed.")

I also tried the above sendCommand() and then publish() versions but I’m not getting anything in my mosquitto broker.

I’m also unclear on if i need a “/” in front of my topic house/dining/temperature - it seems most examples have a leading “/” so I tried both ways.

@watou you seem to be the MQTT expert, what am I be missing?
Anyone else have ideas?
I’m running openhab 1.8 (build from 2016.01.21) on Raspberry Pi 2.

I think you are missing the “trigger” property in your item definition (take a look at the Wiki).

I have not tried this, but I believe the correct syntax for what you are trying to do would be something along the lines of this:

Number MQTToutDiningRoomTemp "MQTTout Dining Room Temp [%.1f °F]" <temperature> (jt,jtmqtt) { mqtt=">[rpiopenhabbroker:house/dining/temperature:state:*:default]" }

Notice the “:*:” that is inserted between “state” and “default”. With this in place, I think your rule should give the expected result.

A leading “/” constitutes an empty top-level in your topic string. This is allowed, but not recommended (as I read the documentation). Whether you choose to use a leading “/” or not, you need to make sure you are being consistent between all your publishers and subscribers.

Here is a thread on how to do it with a single openHAB item!

Pressed for time atm, but it works well.

Thank you both - I am now at least able to transfer data.
I upgraded to 1.8.1 via:
sudo apt-get update
sudo apt-get upgrade

and now the script version works with:

This isn’t urgent but some day I would like to again try @watou 's “items” file method but I’m doing something wrong:

Number DiningRoomTemp "Dining Room Temp [%.1f °F]" <temperature> (all,jtmqtt) { ecobee="<[012345678901#remoteSensors(Dining Room).capability(temperature).value]" }, { mqtt=">[rpiopenhabbroker:house/dining/temperature:state:*:default]" }

That method might be more attractive because I will be relaying around 50 or more items from various bindings to MQTT - perhaps that is more efficient?

No rush but if anyone has any more input on the above “items” file method please let me know.

Too many curly braces! Binding strings all live in a single set of curly braces:

Number DiningRoomTemp	"Dining Room Temp [%.1f °F]" 		<temperature>	(all,jtmqtt) { ecobee="<[012345678901#remoteSensors(Dining Room).capability(temperature).value]", mqtt=">[rpiopenhabbroker:house/dining/temperature:state:*:default]" }