Is it possible to have a sensor only scan at a specific time of day? Or should I be looking into something other than a sensor for this?
I have a Wemo Insight that has a “today_kwh” property, but the default wemo component in home assistant creates a sensor that scans every 10 minutes and it shows a histogram with lots of colors from when it took a reading every 10 minutes.
The way the Wemo works is it will keep adding up the usage and “today_kwh” will keep getting larger until midnight when it resets back to 0 again.
I want to track my daily power usage and calculate an average, ideally displaying something useful in the UI instead of the raindbow histogram that I have now. I thought about using a sensor with a scan interval but if I start my home assistant instance up at 8pm, I still need to take the reading between 11-12, not 8pm the next day.
Still a bit new to home assistant, especially doing custom stuff. I wrote with a basic python script that does a SOAP request to the Wemo which returns back the insight stats. I just need a way to run this at specific time every day and show the results in the UI. My apologies, Python isn’t my strongest language so please feel free to offer any suggestions/improvements.
/config/wemo.py:
import requests, xmltodict, sys
def getWemoInightStat(ip, stat):
url = "http://%s:49153/upnp/control/insight1" % (ip)
headers = {'content-type': 'text/xml','SOAPAction':'"urn:Belkin:service:insight:1#GetInsightParams"'}
body = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetInsightParams xmlns:u="urn:Belkin:service:insight:1"/></s:Body></s:Envelope>'
response = requests.post(url,data=body,headers=headers)
doc = xmltodict.parse(response.content)
result = doc['s:Envelope']['s:Body']['u:GetInsightParamsResponse']['InsightParams']
parts = result.split('|')
stats = {}
stats['state'] = parts[0]
stats['onfor'] = parts[2]
stats['currentmw'] = parts[7]
stats['todaymw'] = parts[8]
stats['totalmw'] = parts[9]
print(stats[stat])
if __name__ == "__main__":
ip = sys.argv[1]
stat = sys.argv[2]
getWemoInightStat(ip, stat)