Page 1 of 1

Python plugin: modbus TCP - return negative values when the solar system return 0

Posted: Friday 14 June 2019 15:36
by pf1979
I'm using modbus-read (v1.2.0) , to retrieve the power generated by a SMA sunny boy 1.5 inverter with success. However when the power generated is zero (at night for instance), I start having negative values.

Domoticz version: 4.10717
Python version: 3.5.3
HW Configuration:
hw.png
hw.png (184.8 KiB) Viewed 1198 times
Screenshot in the end of a production day: (4w)
4w.png
4w.png (63.02 KiB) Viewed 1198 times
Example when the sensor should be zero:
negative usage.png
negative usage.png (67.6 KiB) Viewed 1198 times

Do you have any idea ... something I can adjust? Have you ever been through something similar?
If you need more information, please let me know.

Thanks

Re: Python plugin: modbus TCP - return negative values when the solar system return 0

Posted: Sunday 30 August 2020 15:36
by giton
Hello, I have got the same problem as yours.

The negative value you have is due to the fact than your solar system produce « 0 » and instead of sending « 0 » to Domoticz, it send an hexa value « 0x8000 0000 »; it corresponds in signed decimal to « -2147483648 ». This code corresponds to the NaN (not a number) value of your solar system; you should probably find it in the documentation of your solar system.

Here what I have done to get « 0 » instead of this negative value. As Domoticz doesn’t look like being able to deal with NaN value as it cannot be set as a parameter in the Domoticz configuration, nor in the plugin mod is I use, I have created a TRIGGER at DB level to change the negative value to « 0 ».

I have run the following command in ssh session on my Raspberry:

(You have to replace « 44 » with the idx of your concerned device » and adapt path to your Domoticz DB).
If you have trouble after adding the trigger (ie: values are not anymore update for some or all devices) you can remove it with the following command:

Code: Select all

# sqlite3 /home/pi/domoticz/domoticz.db
drop trigger SetNaNToZeroForIdx44;
Here how to add the trigger:

Code: Select all

# sqlite3 /home/pi/domoticz/domoticz.db
CREATE TRIGGER SetNaNToZeroForIdx44 after UPDATE
ON DeviceStatus
WHEN NEW.ID=44
AND CAST(NEW.sValue AS INT) < 0
BEGIN 
UPDATE DeviceStatus SET sValue=0 WHERE ID=44;END;