Re: Moon phase
Posted: Wednesday 04 January 2017 19:43
A solution for the api kill:
viewtopic.php?f=38&t=8979
Please ...
The icons include a how to....
xxx
viewtopic.php?f=38&t=8979
Please ...
The icons include a how to....
xxx
wizjos wrote:Thanks @alexsh1!
I used your script and modified it somewhat![]()
The result looks like this: MoonPhase.PNG
As you can see with a Custom sensor that represents the actual moonphase as an icon![]()
Code: Select all
-- MoonPhase script ...... os.execute('curl -s -i -H "Accept: application/json" "http://"'..DOMO_IP..'":"'..DOMO_PORT..'"/json.htm?type=setused&idx="'..idxmoonphaseicon..'"&name=Maanfase&description=&switchtype=0&customimage="'..moonPhaseIcon..'"&devoptions=1;%20&used=true"') print("Phase:\t"..moonPhase) ...
Can anyone help me where to find the icons? Because that is the nicest visible part in this script in my opinion.Derik wrote:A solution for the api kill:
https://www.domoticz.com/forum/viewtopi ... =38&t=8979
Please ...
The icons include a how to....
xxx
Really no one can point me to a location where to find the pictures?bertbigb wrote:Can anyone help me where to find the icons? Because that is the nicest visible part in this script in my opinion.Derik wrote:A solution for the api kill:
https://www.domoticz.com/forum/viewtopi ... =38&t=8979
Please ...
The icons include a how to....
xxx
You have also contributed to creating a similar script used with Dashticz. Together with Dashticz, it works fine. But Dashticz does not always fit on my older devices. So it would be nice if the icon (custom text sensor Domoticz GUI) could be adjusted.wizjos wrote:Thanks @alexsh1!
I used your script and modified it somewhat.
As you can see with a Custom sensor that represents the actual moonphase as an icon
https://www.domoticz.com/wiki/Dashticz_ ... plicationsassenzuid wrote:How to configure domoticz to show the correct icon(s)
Code: Select all
"""
<plugin key="Lune" name="Lune" author=" " version="1.0.0" wikilink="http://www.domoticz.com/wiki/plugins/" externallink=" ">
<params>
<param field="Mode1" label="Key WU" width="200px" required="true" default="5ea448da70b1136f"/>
<param field="Mode2" label="Code Country" width="100px" required="true" default="fr"/>
<param field="Mode3" label="City" width="300px" required="true" default="paris"/>
<param field="Mode4" label="Polling interval (minutes, 30 mini)" width="40px" required="true" default="2"/>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="True" value="Debug"/>
<option label="False" value="Normal" default="True" />
</options>
</param>
</params>
</plugin>
"""
import Domoticz
# import urllib
# from urllib.request import request, urlopen
import urllib.request
import json
from datetime import datetime
from datetime import timedelta
icons = {"nouvelle": "nouvelle.zip",
"precroi": "precroi.zip",
"prequar": "prequar.zip",
"gibcroi": "gibcroi.zip",
"pleine": "pleine.zip",
"gibdecroi": "gibdecroi.zip",
"derquar": "derquar.zip",
"dercroi": "dercroi.zip"}
# New/Waxing Crescent/First Quarter/Waxing Gibbous/Full/Waning Gibbous/Last Quarter/Waning Crescent
# nouvelle/precroi/prequar/gibcroi/pleine/gibdecroi/derquar/dercroi
class BasePlugin:
def __init__(self):
self.debug = False
self.nextupdate = datetime.now()
self.pollinterval = 60 # default polling interval in minutes
self.error = False
return
def onStart(self):
global icons
Domoticz.Debug("onStart called")
if Parameters["Mode6"] == 'Debug':
self.debug = True
Domoticz.Debugging(1)
DumpConfigToLog()
else:
Domoticz.Debugging(0)
# load custom battery images
for key, value in icons.items():
if key not in Images:
Domoticz.Image(value).Create()
Domoticz.Debug("Added icon: " + key + " from file " + value)
Domoticz.Debug("Number of icons loaded = " + str(len(Images)))
for image in Images:
Domoticz.Debug("Icon " + str(Images[image].ID) + " " + Images[image].Name)
# create the mandatory child device if it does not yet exist
if 1 not in Devices:
Domoticz.Device(Name="Lune", Unit=1, TypeName="Custom",
Options={"Custom": "1;"},
Used=1).Create()
# check polling interval parameter
try:
temp = int(Parameters["Mode4"])
except:
Domoticz.Error("Invalid polling interval parameter")
else:
if temp < 1:
temp = 1 # minimum polling interval
Domoticz.Error("Specified polling interval too short: changed to 30 minutes")
elif temp > 1440:
temp = 1440 # maximum polling interval is 1 day
Domoticz.Error("Specified polling interval too long: changed to 1440 minutes (24 hours)")
self.pollinterval = temp
Domoticz.Log("Using polling interval of {} minutes".format(str(self.pollinterval)))
def onStop(self):
Domoticz.Debug("onStop called")
Domoticz.Debugging(0)
def onHeartbeat(self):
now = datetime.now()
if now >= self.nextupdate:
self.nextupdate = now + timedelta(minutes=self.pollinterval)
# data=json.loads(urllib.request.urlopen("http://api.wunderground.com/api/5ea448da70b1136f/astronomy/q/fr/paris.json").read().decode('ascii'))
data = json.loads(urllib.request.urlopen(
"http://api.wunderground.com/api/" + Parameters["Mode1"] + "/astronomy/q/" + Parameters["Mode2"] + "/" +
Parameters["Mode3"] + ".json").read().decode('ascii'))
lune = data['moon_phase']['phaseofMoon']
# Domoticz.Log(str(lune))
self.UpdateDevice(lune)
# New/Waxing Crescent/First Quarter/Waxing Gibbous/Full/Waning Gibbous/Last Quarter/Waning Crescent
# nouvelle/precroi/prequar/gibcroi/pleine/gibdecroi/derquar/dercroi
def UpdateDevice(self, lune):
# Make sure that the Domoticz device still exists (they can be deleted) before updating it
if 1 in Devices:
if lune == "New":
icon = "nouvelle"
datafr = "nouvelle lune"
elif lune == "Waxing Crescent":
icon = "precroi"
datafr = "premier croissant"
elif lune == "First Quarter":
icon = "prequar"
datafr = "premier quartier"
elif lune == "Waxing Gibbous":
icon = "gibcroi"
datafr = "gibeuse croissante"
elif lune == "Full":
icon = "pleine"
datafr = "pleine lune"
elif lune == "Waning Gibbous":
icon = "gibdecroi"
datafr = "gibeuse decroissante"
elif lune == "Last Quarter":
icon = "derquar"
datafr = "dernier quartier"
elif lune == "Waning Crescent":
icon = "dercroi"
datafr = "dernier croissant"
try:
Devices[1].Update(nValue=0, sValue=str(datafr), Image=Images[icon].ID)
except:
Domoticz.Error("Failed to update device")
return
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()
# Generic helper functions
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug("'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
returnSearching the Wunderground forum tells me "This happens when a day does not have a moon rise. In this case, the moon rose yesterday" https://apicommunity.wunderground.com/w ... g-sometime"moonrise": {
"hour":"",
"minute":""
}
see also: http://www.domoticz.com/forum/viewtopic ... 67&t=1940464: attempt to concatenate global 'moonriseMinute' (a nil value)
Yes, that did the trick. Changed part:elmortero wrote: Wednesday 13 September 2017 19:44 something like if moonriseMinute == nil then moonriseMinute = '--' end (and same for the rest of the fetched values)
That should avoid giving an error and in your textsensor would get --:--
Code: Select all
-- moonrise
moonriseHour, moonriseMinute = string.match(s, [["moonrise": {"hour":"(%d+)","minute":"(%d+)"]])
if moonriseHour == nil then moonriseHour = '--' end
if moonriseMinute == nil then moonriseMinute = '--' end
if debug then print("Moonrise:\t"..moonriseHour..":"..moonriseMinute) end
-- moonset
moonsetHour, moonsetMinute = string.match(s, [["moonset": {"hour":"(%d+)","minute":"(%d+)"]])
if moonsetHour == nil then moonsetHour = "--" end
if moonsetMinute == nil then moonsetMinute = "--" end
if debug then print("Moonset:\t"..moonsetHour..":"..moonsetMinute) endI've one default on my keyboardEdwinK wrote: Wednesday 13 September 2017 20:49 Thanks. Seems to work again
(Why don't we have a 'thanks' button in here?)![]()