I have several energy meters, (connected with my LAN) which are not supported by Indigo. However with a python script I'm able to retrieve the values and store these in variables for further use (graphs, reports)
The script is included as "Embedded Python" in a Schedule that runs every minute. Sometimes I see a time-out warning in my log file.
I want to move the python script to an external file, but have to make it robust to avoid a crash off the computer if the connection cannot be made.
Here is (a part of) the script (Total script is much longer, but my problem is in this part)
----
#! /usr/bin/python
# --------------------------------------------------
# PREPARATION & SETTINGS
# --------------------------------------------------
import urllib2
import urllib
import base64
import json
import sys
# --------------------------------------------------
# READING YOULESS PV panels
# --------------------------------------------------
URL = 'http://192.168.178.71/a'
response = urllib.urlopen(URL).read()
# typical output consists of four lines
#
# 1195,497 kWh
# 93 Watt
# 123
# OK (260)
lines = response.split("\n") # split the 4 lines into elements
lines[0]=lines[0].lstrip(" ")
Watt_zon = lines[1].split(" ")[0]
kWhText= lines[0].split(" ")[0]
kWhdeel=kWhText.split(",")
kWhzon=kWhdeel[0] + "." + kWhdeel[1]
indigo.variable.updateValue("kWh_zon" , value = kWhzon)
indigo.variable.updateValue("Watt_zon" , value = Watt_zon)
# --------------------------------------------------
# last line off script
# --------------------------------------------------
Question: How to force a timeout in this script, if the connection with the meter fails?
response = urllib.urlopen(URL, timeout=1).read() does not work.
PS: the non-supported meters are a Youless ( https://www.youless.nl/downloads-ls110.html) and a Beeclear (https://beeclear.nl) (Sorry, both sites in Dutch )