Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mihome_energy_monitor power readings not working #75

Closed
whaleygeek opened this issue Jun 8, 2016 · 11 comments
Closed

mihome_energy_monitor power readings not working #75

whaleygeek opened this issue Jun 8, 2016 · 11 comments
Labels

Comments

@whaleygeek
Copy link
Owner

Mark reported that the mihome_energy_monitor.py example reports:

Incoming from (4, 2, 911)
No route to an object, for device:(4, 2, 911)
message from unknown device:(4, 2, 911)

@whaleygeek
Copy link
Owner Author

The issue here is that the example code iterates through the registry, but the registry is a list of devices that you own, not necessarily a list of devices that are connected up to your code.

To create an object that can store values, you have to call registry.get() which creates an instance of that object, and also knits up a receive route. Under the bonnet, the registry might already have a cached object for convenience, but it is not knitted up to the receive router (fsk_router), so when a message comes in from it, it will be logged as an unknown device.

The workaround at the moment is to make sure you 'get' it from the registry, which makes the object active. The examples control_any_auto, control_any_reg and control_any_noreg show various ways to do this.

I will look back at the energy monitor example and improve and correct it so that it causes the receive routes to be knitted to real objects.

@whaleygeek whaleygeek added the bug label Jun 8, 2016
@whaleygeek
Copy link
Owner Author

e.g. if your device is in the registry named as 'tv', try something like this:

import energenie
import time

tv = energenie.registry.get('tv')

energenie.init()
while True:
energenie.loop()
p = tv.get_power()
print(p)
time.sleep(1)

@hudsonkk
Copy link

hudsonkk commented Jan 4, 2017

Hi whaleygeek

I've just started learning python as part of my project to use energenie products around my home. I'm trying to generate a script that will just turn off the MIHO005 via the ENER34RT on my Pi.

I'm having difficulty in translating the code here into code that delivers what I need, specifically I'm receiving a keyError as shown below (I've tried a range of device and name combinations and looked into the kvs.py, devices.py and registry.py files to understand how the key is generated).

I hope it's ok to ask for guidance here, if so could you point me in the right direction please?

Code:

def off():

key = "Monitor1 MIHO005(0xffff7a)"
device = energenie.registry.get(key)

device ="Monitor1 MIHO005(0xffff7a)"

device = auto_0x2_0xffff7a

print"Turning off %s" % device

device.turn_off()

if name == "main":

energenie.init()
try:
    off()
finally:
    energenie.finished()

Error:
File "/home/pi/pyenergenie-master/src/energenie/Registry.py", line 63, in get
c = self.store[name]
File "/home/pi/pyenergenie-master/src/energenie/KVS.py", line 103, in getitem
return self.store[key]
KeyError: 'Monitor1 MIHO005(0xffff7a)'

@whaleygeek
Copy link
Owner Author

whaleygeek commented Jan 4, 2017 via email

@hudsonkk
Copy link

hudsonkk commented Jan 4, 2017

Thanks for the guidance. I have this in the registry.kvs

ADD Mon1
type=MIHO005
device_id=16777082

I'm now getting the error NameError: global name 'Mon1' is not defined

The code is


import time
import energenie
##from energenie.lifecycle import *

#===== GLOBALS =====

quit = False

#===== INPUT METHODS ==========================================================

try:
    readin = raw_input # Python 2
except NameError:
    readin = input # Python 3

def off():
        Mon1.off()

if __name__ == "__main__":

    energenie.init()
    try:
        off()
    finally:
        energenie.finished()

I'm stumped.

@whaleygeek
Copy link
Owner Author

whaleygeek commented Jan 4, 2017 via email

@hudsonkk
Copy link

hudsonkk commented Jan 5, 2017 via email

@whaleygeek
Copy link
Owner Author

whaleygeek commented Jan 5, 2017 via email

@hudsonkk
Copy link

hudsonkk commented Jan 5, 2017

That's great advice - I just had to amend off to turn_off and capitalise Devices and it works!

import energenie

tv = energenie.Devices.MIHO005(16777082)

energenie.init()

tv.turn_off()

energenie.finished()

`
This is the right level for me and something that I can build on.

Thanks for your help with this.

@whaleygeek
Copy link
Owner Author

whaleygeek commented Jan 5, 2017 via email

@whaleygeek
Copy link
Owner Author

Looks like this issue is now fixed so I will close, but please re-open if I missed anything @hudsonkk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants