iancmcc/ouimeaux

Insight Switch Examples? <Solved>

Closed this issue · 2 comments

Could someone please provide an example on how to call the Insight methods?
I have the basics, for example calling for the state of my switch:

>>>env.start()
>>>env.discover(seconds=3)
>>>env.list_switches()
dict_keys(['MyWeMo'])
>>>sw = env.get_switch('MyWeMo')
>>>sw.get_state()
1

But I have no idea how to call for the insight data
This is the closest I have gotten to getting the KWH data
Obviously I am doing something wrong but I have not idea how to do it correctly

>>>print(sw.insight.GetTodayKWH())
{'faultcode': 's:Client', 'faultstring': 'UPnPError', 'detail': '\n'}

Please advise.

I got it! Here is the answer for anyone else looking to do this.
The insight data is retrieved via attributes, not functions

>>> insightSwitch = env.get_switch('MyWeMo')
>>>insightSwitch.get_state()
1
>>> insightSwitch.today_kwh
0.29820668929746696
>>> insightSwitch .today_on_time
6062
>>> insightSwitch.today_on_time/60/60
1.6902777777777778
>>> insightSwitch.last_change
2018-02-14 00:57:03
>>> insightSwitch.insight_params
{'state': '1', 'lastchange': datetime.datetime(2018, 2, 14, 0, 57, 3), 'onfor': 5658, 'ontoday': 6179, 'ontotal': 6054, 'todaymw': 18203394, 'totalmw': 18203394, 'currentpower': 158855}

@craig1971 Do you happen to know if this is possible to get as well via the REST API?