Moon phase

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Moon phase

Post by Derik »

A solution for the api kill:
viewtopic.php?f=38&t=8979


Please ...
The icons include a how to....

xxx
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: Moon phase

Post by Minglarn »

wizjos wrote:Thanks @alexsh1!
I used your script and modified it somewhat :mrgreen:

The result looks like this: MoonPhase.PNG
As you can see with a Custom sensor that represents the actual moonphase as an icon 8-)

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)
...


Hi! I'm planing to write a php script for moonphase. I've got it running and even show the right moon phase picture.
I was lurking around in the forum and saw you script and got curious when I noticed the this line in your code !

Is this a new function for domoticz?

So it is possible to change icon/picture with a JSON url ?
As I dont really understand you code, could you please explain the right URL to change the icon for me?
When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
bertbigb
Posts: 147
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Moon phase

Post by bertbigb »

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
Can anyone help me where to find the icons? Because that is the nicest visible part in this script in my opinion.
Best regards Bert

Synology DS1517+ - DSM 6.2
Raspberry PI2-B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon
bertbigb
Posts: 147
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Moon phase

Post by bertbigb »

bertbigb wrote:
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
Can anyone help me where to find the icons? Because that is the nicest visible part in this script in my opinion.
Really no one can point me to a location where to find the pictures?
Best regards Bert

Synology DS1517+ - DSM 6.2
Raspberry PI2-B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Moon phase

Post by Derik »

@ bert i do also not have the icons...:-(
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Moon phase

Post by assenzuid »

Someone able to share the icon set and how to implement?
Hesmink
Posts: 168
Joined: Monday 22 June 2015 10:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Moon phase

Post by Hesmink »

Tiny issue: If you happen to live in a city with a space in the name, you have to escape the space to make it work, like:

local city = "Den%20Haag"
User avatar
Eddiever
Posts: 105
Joined: Thursday 27 April 2017 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: The Netherlands (Hoogeveen)
Contact:

Re: Moon phase

Post by Eddiever »

Scratching my head. Dunno what I missed. I used the wiki page to implement the moonphase. But I get this error:
moon.PNG
moon.PNG (11.14 KiB) Viewed 5149 times
Figured it out. Stupid mistake, Made an error in adjusting City (hard to know your own city were one lives for over 40 years :D )
bertbigb
Posts: 147
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Moon phase

Post by bertbigb »

From the last error message I also could find out where to find the icons:

The icons for the moonphase can be found at https://github.com/robgeerts/dashticz_v2

They are part of the dashticz web interface
Best regards Bert

Synology DS1517+ - DSM 6.2
Raspberry PI2-B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Moon phase

Post by assenzuid »

How to configure domoticz to show the correct icon(s)
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Moon phase

Post by Jan Jansen »

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
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.
I already have a user variable "MoonPicture" (current value: moon.59.png). The relevant icons can be found at https://github.com/robgeerts/dashticz_v2 I assume that these icons can be uploaded using the "custom icon uploader" (am I right??). Is it possible to customize the code to make use of the user variable "MoonPicture"?

Thanks in advance!

Jan
natywna
Posts: 2
Joined: Tuesday 20 June 2017 20:01
Target OS: Linux
Domoticz version:
Contact:

Re: Moon phase

Post by natywna »

Nice work! In full moon I was always a little bit weird and slep not too good.
User avatar
Eddiever
Posts: 105
Joined: Thursday 27 April 2017 20:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: The Netherlands (Hoogeveen)
Contact:

Re: Moon phase

Post by Eddiever »

assenzuid wrote:How to configure domoticz to show the correct icon(s)
https://www.domoticz.com/wiki/Dashticz_ ... plications
See the link above, but this is for Dashticz. I had a some troubles getting it to work but it does now and I love it!
jackslayter
Posts: 59
Joined: Tuesday 07 October 2014 11:00
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: France RA
Contact:

Re: Moon phase

Post by jackslayter »

hi,
I try to make a plugin for moon phase but I have problem with python

error in dz log : "Error: (Lune) Failed to update device"

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 + "'")
    return
and icons for test https://drive.google.com/file/d/0B3QY9M ... sp=sharing

thank you
RPi2 + RFLink, Domoticz
Chacon - micromodule 200w, remote 3b, 2x module 1000w, remote 16b, smoke detector, door contact, 2x 3500w plug
Oregon - 3x Thgr122Nx / OWL - CM180 / TRC02_2 RGB / Cheap - PiR, door contact, Temp Hum / 4x REVOLT NC5461
tottka
Posts: 19
Joined: Wednesday 19 July 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: US
Contact:

Re: Moon phase

Post by tottka »

Fantastic thread & thank you for the work you did on this.
I'm wondering how you determined the internal icon numbers?
I think I understand most of what you did & I'm ready to give it a go.
thanks
User avatar
htilburgs
Posts: 464
Joined: Tuesday 03 November 2015 11:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Moon phase

Post by htilburgs »

In some rare occassions (like today :) ) the "moonrise" hour and minute are empty
"moonrise": {
"hour":"",
"minute":""
}
Searching 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

I'm looking for a way to modify the lua script, so the script keeps running and not the error
64: attempt to concatenate global 'moonriseMinute' (a nil value)
see also: http://www.domoticz.com/forum/viewtopic ... 67&t=19404
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Moon phase

Post by elmortero »

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 --:--
User avatar
htilburgs
Posts: 464
Joined: Tuesday 03 November 2015 11:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Moon phase

Post by htilburgs »

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 --:--
Yes, that did the trick. Changed part:

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) end
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Moon phase

Post by EdwinK »

Thanks. Seems to work again


(Why don't we have a 'thanks' button in here?) ;)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
htilburgs
Posts: 464
Joined: Tuesday 03 November 2015 11:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Moon phase

Post by htilburgs »

EdwinK wrote: Wednesday 13 September 2017 20:49 Thanks. Seems to work again


(Why don't we have a 'thanks' button in here?) ;)
I've one default on my keyboard ;-)
thanks.jpg
thanks.jpg (8.44 KiB) Viewed 4424 times
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests