sclavel / homebridge-modbus

Homebridge plugin to interface with any modbusTCP
8 stars 14 forks source link

Add Scale Factor read and write register #3

Closed Pascalx77 closed 3 years ago

Pascalx77 commented 3 years ago

Hi,

First, thank you for this Plugins, I use it at my Home really, really great. I am new with homebridge and Github, I am discovering this.

I was wondering how to implement an advance feature for read and write register, to add a scale factor. Example: The value in my ModbusTCP device are in tenth of degre celcius, 21.3 degC = 213. With a scale factor I could enter 0.1 to correct the value and vice-versa for setpoint enter 10.

Or is there is an other simpler solution?

Regards,

berkus commented 3 years ago

@Pascalx77 you could find that version in here https://github.com/AlekseevAV/homebridge-modbus

I'm planning to publish a variation of this to npm to make it easier install on HomeBridge.

eliziox commented 3 years ago

Hello Berkus

I tried to use your correction, but I have the following errors :

[4/1/2021, 9:31:16 PM] [Modbus] Connection lost [4/1/2021, 9:31:21 PM] [Modbus] Reconnecting to 192.168.1.100 [4/1/2021, 9:31:21 PM] [Modbus] Socket connected [4/1/2021, 9:31:22 PM] [Modbus] error reading modbus { cmd: 'r', type: 'r', add: 1, count: 3 } UserRequestError { err: 'ModbusException', message: 'A Modbus Exception Occurred - See Response Body', response: ModbusTCPResponse { _id: 140, _protocol: 0, _bodyLength: 3, _unitId: 1, _body: ExceptionResponseBody { _fc: 3, _code: 1 } } } [4/1/2021, 9:31:22 PM] [Modbus] Connection lost

Can you advise please?

Thanks

JSP

Le 14 mars 2021 à 13:56, Berkus Decker @.***> a écrit :



@Pascalx77https://github.com/Pascalx77 you could find that version in here https://github.com/AlekseevAV/homebridge-modbus

I'm planning to publish a variation of this to npm to make it easier install on HomeBridge.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/sclavel/homebridge-modbus/issues/3#issuecomment-798902239, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AP3TLZMWL73WK7RHXZ3ODITTDSXADANCNFSM4PDBB3FA.

sclavel commented 3 years ago

an optional scale parameter is now available in 1.0.2

berkus commented 3 years ago

👍🏼 thank you!

m4rkv5 commented 2 years ago

@sclavel I can't get scale to work nothing happens. Config 1:

{
    "name": "Außen",
    "type": "TemperatureSensor",
    "CurrentTemperature": {
        "address": "r10201",
        "scale": 100
    }
}

Error:


[4/18/2022, 11:49:28 PM] [Modbus] Außen Current Temperature 100 => 1327
[4/18/2022, 11:49:28 PM] [homebridge-modbus] This plugin generated a warning from the characteristic 'Current Temperature': characteristic was supplied illegal value: number 1327 exceeded maximum of 100. See https://git.io/JtMGR for more info.```
m4rkv5 commented 2 years ago

Perhaps both need do be named map and not modbusMap?

if ('scale' in modbusMap) {
      val = val / modbusMap.scale;
    }
if ('mask' in map) {
      val = val & map.mask;
    }
sclavel commented 2 years ago

Scale is a multiplier. "scale": 2, will multiply the modbus value by 2. "scale": 0.5, will divide the modbus value by 2.

On Tue, Apr 19, 2022 at 1:54 AM m4rkv5 @.***> wrote:

@sclavel https://github.com/sclavel I can't get scale to work. I tried two different Configs but nothing happens. Config 1:

{

"name": "Außen",

"type": "TemperatureSensor",

"CurrentTemperature": {

    "address": "r10201",

    "scale": 100

}

}

Config 2:

{

"name": "Außen",

"type": "TemperatureSensor",

"CurrentTemperature": {

    "address": "r10201",

    "scale": "100"

}

}

Error:

[4/18/2022, 11:49:28 PM] [Modbus] Außen Current Temperature 100 => 1327

[4/18/2022, 11:49:28 PM] [homebridge-modbus] This plugin generated a warning from the characteristic 'Current Temperature': characteristic was supplied illegal value: number 1327 exceeded maximum of 100. See https://git.io/JtMGR for more info.```

— Reply to this email directly, view it on GitHub https://github.com/sclavel/homebridge-modbus/issues/3#issuecomment-1101798287, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQV34ENCEU3SYNXQR3JFNTVFXKYZANCNFSM4PDBB3FA . You are receiving this because you were mentioned.Message ID: @.***>

m4rkv5 commented 2 years ago

@sclavel I fixed my issues renaming modbusMap.scale to map.scale in line 314.

eliziox commented 1 year ago

Scale is diviser and not multiplier for register

10 = divised by 10