How to send Float values to Domoticz instead of Integers ?

Python and python framework
Post Reply
aerno
Posts: 2
Joined: Saturday 10 February 2018 14:55
Target OS: Linux
Domoticz version:
Contact:

How to send Float values to Domoticz instead of Integers ?

Post by aerno » Saturday 10 February 2018 15:24

I'm coding an SDM630 smart meter plugin for energy usage and return for Domoticz at the moment. See attached screenshot.

It is working fine, except that i can only update Integer values instead of Floats.

For updating I use this piece of code.

Code snippet:

row = line.split('\t')

# Watts 1
s="%.1d; %d" % (float(row[7]), 0)
Devices[7].Update(nValue=int(float(row[7])), sValue=s)

'row' contains the fields of a TAB separated ASCII output record from the SDM630 meter.

I have 2 questions:

- I tried sending nValue=float(row[7]). That gives me a type error. How do I update a float value using a float ?

- How do I set the SubTypeName of the Current meter ? I used TypeName 'Current/Ampere'. It currently shows up as a 'CM113/ElectriSave', which I don't have.

Ps. Forgive me my high energy usage ;-) At the moment we're heating our Swedish house directly on electricity using a 2 phase heater. Here in Sweden one pays alot extra to the electricity network company if you're a netto producer over the year. So we have to burn our 500kWh PV overproduction of last summer :roll: Using roughly 60kWh a day it will be done in about 8 days 8-)
sdm630.png
sdm630.png (146.78 KiB) Viewed 576 times

Barberousse
Posts: 111
Joined: Wednesday 02 December 2015 22:47
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: How to send Float values to Domoticz instead of Integers ?

Post by Barberousse » Thursday 01 March 2018 11:51

aerno wrote:
Saturday 10 February 2018 15:24
Devices[7].Update(nValue=int(float(row[7])), sValue=s)

- I tried sending nValue=float(row[7]). That gives me a type error. How do I update a float value using a float ?
nValue accepts integers only, you can't pass float with it. Usually, you pass float using sValue, but it is really up to the device type. You should try virtual devices and check which type is using nValue, which gets its value from sValue, and use the correct device type from your plugin.

aerno
Posts: 2
Joined: Saturday 10 February 2018 14:55
Target OS: Linux
Domoticz version:
Contact:

Re: How to send Float values to Domoticz instead of Integers ?

Post by aerno » Thursday 11 October 2018 13:49

Thanx. Currently still on integer values only. Floats would be nicer.

User avatar
Dnpwwo
Posts: 767
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: How to send Float values to Domoticz instead of Integers ?

Post by Dnpwwo » Friday 12 October 2018 3:27

@aerno,

Have a look at https://github.com/dnpwwo/Domoticz-RAVE ... /plugin.py which writes to a couple of power consumption devices.

For historical reasons not all the Domoticz devices handle data the same way and the Python Framework has not attempted to fix it, it just exposes the Devices as they are.

I looked at these devices a long time ago and this code:

Code: Select all

Devices[2].Update(nValue=0, sValue=sFloat.replace('.',''))
worked for me :o . From your extract below you might try something like:

Code: Select all

Devices[7].Update(nValue=0, sValue=str(float(row[7])))
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw

Post Reply

Who is online

Users browsing this forum: lwolf, moroen and 3 guests