Help with modbus binding and transformation

Tags: #<Tag:0x00007f745376ce50>

You mean in the PaperUI Control tab?
You cannot. PaperUI is system administrator interface, shows all sorts of things in the way it feels like.

In an end-user UI, of course, you can format numbers for display. For BasicUI for example, you would add a formatter like [%.1f °C] to the label of your temperature Item.
"My pool temperature [%.1f °C]"

You mean in the PaperUI Control tab?
You cannot. PaperUI is system administrator interface, shows all sorts of things and allows you to control them.

In an end-user UI, of course, you can make something display only. In BasicUI for example, you would use a Text widget in your sitemap file to display your temperature Item.

Hello,

for me it’s looks like strange. I have modbus and onewire.
when I get variable from one-wire, and devine it as type temperature I see in in paperUI 22.5 °C, and i’ts blocked for modifying.

when I get variable from modbus, and alse set it as temperature, then I see only as a number (like in previous message)

image

Ed

Some bindings know about the devices they are connected with, and can supply some default details to openHAB.

Modbus binding will never do that because there is no identification, no discovery. Register 32978 is just a number that may represent a water depth gauge or the age of the Earth, it cannot guess.

What would you like to happen now?

Hello,

that’s clear. but I set in paperUI number:Temperature. and expect to see 22.5 °C instead just a number 23. so, openhab don’t need to guess :slight_smile:

Ed

Modbus binding channels do not support units of measurement.

Perhaps one day there will be a system profile that you can apply to a channel to convert a plain number to a number with units. But not today.

You can control the display format as already described.

Hello,

ok, now I create .items file with my variable, and link them. works fine.
but is it possible to have read/only item? do not allow to modify.

Ed

Yes.

In your UI you would choose a display only widget.

In your rules, you take care not to send commands or updates to the Item.

Hello,

I am still about PaperUI.
I have temperature from one-wire, and this one in paperUI is read/only. I can’t modify.
How to setup same variable from modbus? is it possibloe in paperUI?

Ed

PaperUI is an adminstrator’s interface. It is supposed to give access to things you would not expose to an “ordinary” user. Why would you need read-only access, when only trusted people should be there to begin with?

There would be no point in a read only Item. It would be NULL forever. Some part of openHAB needs to able to write to it.

Are you talking about a read-only channel? Some bindings will provide those, depending on the configuration and technology behind them.

Modbus data Thing channels are always read/write. You may or may not configure the data Thing to be read-only, write-only, or read/write. That doesn’t affect any Item you may link a channel to.

Can I add custom channels to modbus?

You could fork your own version of the binding if you want.

What channel do you want? It’s pretty flexible as it is.

A reminder that linking a read-only channel to an Item does not make the Item read-only.

hello,

i need something like this:

<thing-type id="neostat">
		<label>Pool</label>
		<description>Pool Thermostat</description>
		<channels>
			<channel id="PoolTemperature" typeId="Pooltemperature">
		        <label>Current Pool Temperature</label>
        		<description>Actual Pool temperature</description>
			</channel>

			<channel id="setPoolTemperature" typeId="setPoolTemperature">
		   		<label>Set Pool Temperature</label>
   				<description>Target temperature setting for the pool</description>
			</channel>

		</channels>

	</thing-type>

	<channel-type id="Pooltemperature">
		<item-type>Number:PoolTemperature</item-type>
		<label>Temperature</label>
		<description>Measured temperature value</description>
   		<state pattern="%.1f %unit%" readOnly="true" />
	</channel-type>

	<channel-type id="setPointTemperature">
   		<item-type>Number:setPointTemperature</item-type>
   		<label>Set Temperature</label>
		<description>Target temperature setting for the room</description>
   		<state min="5" max="40" step="0.1" pattern="%.1f %unit%" readOnly="false" />
	</channel-type>

not sure i am right, but this is how i want to see wariables

Why? Things and channels stuff is only of interest to the system administrator. You can set labels, icons, data format etc etc on the Item that you present to end users. If you want a “read only” Item, like a temperature sensor, you simply don’t put any control on the user UI, just a display.

Modbus binding doesn’t generally support all those extras, because there is no discovery about the target device. All Modbus knows about is 16-bit registers; any interpretation of what those mean has to be supplied by us, the openHAB admin.

So you would have to modify your own binding version for that. However, it seems to me you would just be making manual settings in the most difficult way, instead of applying them to the Item.

If you wish, it is possible to create a sort of device-specific template as a binding that uses the background transport mechanisms of the Modbus binding, but provides predefined device-specific channels.
Is this a commercial project where you want to make available a “binding for a Neostat version 3” sort of thing?

hello,

is it possible to get content of modbus regular pool in any debug log/file?
in pool I read data, for example 100 bytes. is it possible to see content of all 100 bytes?

Ed

Hello,

Using your example with bits, I configure things, rules, items… but receiving an errors in executing rule. maybe you can take a look… i can’t find my mistake

modbus.things
Bridge modbus:tcp:id2 [ host=“192.168.10.82”, port=502, id=1, timeBetweenTransactionsMillis=100 ]
{
Bridge poller poolpoll [ start=16, length=33, refresh=1000, type=“holding” ]
{
Thing data reg40017 [ readStart=“16”, readValueType=“uint16”, writeStart=“16”, writeValueType=“uint16”, writeType=“holding”, writeMultipleEvenWithSingleRegisterOrCoil = “true” ]
Thing data bit_16_0 [ readStart=“16.0”, readValueType=“bit” ]
Thing data bit_16_1 [ readStart=“16.1”, readValueType=“bit” ]
Thing data bit_16_2 [ readStart=“16.2”, readValueType=“bit” ]
Thing data bit_16_3 [ readStart=“16.3”, readValueType=“bit” ]
Thing data bit_16_4 [ readStart=“16.4”, readValueType=“bit” ]
Thing data bit_16_5 [ readStart=“16.5”, readValueType=“bit” ]
Thing data bit_16_14 [ readStart=“16.14”, readValueType=“bit” ]
Thing data bit_16_15 [ readStart=“16.15”, readValueType=“bit” ]
}
}

modbus.items
Number reg40017 “reg40017 register [%d]” { channel=“modbus:data:id2:poolpoll:reg40017:number” }
Group reg40017_Bits
Switch reg40017_bit_16_0 “Enable Filtration [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_0:switch” }
Switch reg40017_bit_16_1 “Manual Filter Backwash [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_1:switch” }
Switch reg40017_bit_16_2 “Open Pool [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_2:switch” }
Switch reg40017_bit_16_3 “Close Pool [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_3:switch” }
Switch reg40017_bit_16_4 “Pool Light [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_4:switch” }
Switch reg40017_bit_16_5 “Block Filling Up [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_5:switch” }
Switch reg40017_bit_16_14 “Reset Alarms [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_14:switch” }
Switch reg40017_bit_16_15 “Save Filter Backwash Timers [%s]” (reg40017_Bits) { channel=“modbus:data:id2:poolpoll:bit_16_15:switch” }

modbus.rules
import java.lang.Math // we need this for testBit

rule “update reg40017 register”
when
Member of reg40017_Bits received command
then
var BigInteger register = 0 // we need BigInteger type to use testBit
if ( reg40017.state != NULL && reg40017.state != UNDEF) { // avoid using invalid register image
register = (reg40017.state as DecimalType).toBigDecimal.toBigInteger // use existing image
}
switch triggeringItem.name { // act on switched Item name to change only one bit
case “reg40017_bit_16_0” : {
if (receivedCommand = ON) {
register = register.setBit(0)
} else if (receivedCommand = OFF) { // by testing both, we will ignore REFRESH commands
register = register.clearBit(0)
}
}
case “reg40017_bit_16_1” : {
if (receivedCommand = ON) {
register = register.setBit(1)
} else if (receivedCommand = OFF) {
register = register.clearBit(1)
}
}
case “reg40017_bit_16_2” : {
if (receivedCommand = ON) {
register = register.setBit(2)
} else if (receivedCommand = OFF) {
register = register.clearBit(2)
}
}
}
// at last, write to Modbus
reg40017.sendCommand(register)
end

errors in log when i try to on/off bit 0:
2019-09-19 20:41:38.757 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘update reg40017 register’: An error occurred during the script execution: null
2019-09-19 20:41:38.763 [WARN ] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:id2:poolpoll:bit_16_0 ‘Modbus data’: not processing command OFF since writeStart is missing and transformation output is not a JSON

Ed

seems this string return an error. maybe i need to install someting to use BigInteger ???

Ed

Please use code fences in this forum.

That’s what this part is for
import java.lang.Math
and it used to work?!
Just tried, and nope not working for me eiher.
An alternative import
import java.math.BigInteger
seems to do the job, but that then seems to need another rule change from
var BigInteger register = 0
to
var register = BigInteger.valueOf(0)

The if / else if conditions you copied from the bits example all have typos I’m afraid - sorry.
Should be
if (receivedCommand == ON) {
etc. to test for equalty with ==

That’s not an error, it is just a message that the Thing is ignoring a command because it has no write capability.

It should really “fail” silently. I think i will request it “turned off” in binding - or rather, demoted to DEBUG

Hello,

still error in line 7, I also try to use import java.math.BigInteger

2019-09-22 18:38:28.454 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘update reg40017 register’: The name ‘BigInteger’ cannot be resolved to an item or type; line 7, column 19, length 10

import java.lang.Math

rule “update reg40017 register”
when
Member of reg40017_Bits received command
then
var register = BigInteger.valueOf(0)
if ( reg40017.state != NULL && reg40017.state != UNDEF) {
register = (reg40017.state as DecimalType).toBigDecimal.toBigInteger
}
switch triggeringItem.name { // act on switched Item name to change only one bit
case “reg40017_bit_16_0” : {
if (receivedCommand == ON) {
register = register.setBit(0)
} else if (receivedCommand == OFF) { // by testing both, we will ignore REFRESH commands
register = register.clearBit(0)
}
}
case “reg40017_bit_16_1” : {
if (receivedCommand == ON) {
register = register.setBit(1)
} else if (receivedCommand == OFF) {
register = register.clearBit(1)
}
}

That does not correspond with this

What version of java are you running?

java version “1.8.0_201”
Java™ SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot™ 64-Bit Server VM (build 25.201-b09, mixed mode)