How to send Float values to Domoticz instead of Integers ?

Python and python framework

Moderator: leecollings

Post Reply
aerno
Posts: 3
Joined: Saturday 10 February 2018 13:55
Target OS: Linux
Domoticz version:
Contact:

How to send Float values to Domoticz instead of Integers ?

Post by aerno »

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 1165 times
Barberousse
Posts: 140
Joined: Wednesday 02 December 2015 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

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

Post by Barberousse »

aerno wrote: Saturday 10 February 2018 14: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: 3
Joined: Saturday 10 February 2018 13:55
Target OS: Linux
Domoticz version:
Contact:

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

Post by aerno »

Thanx. Currently still on integer values only. Floats would be nicer.
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

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

Post by Dnpwwo »

@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: No registered users and 1 guest