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.
User avatar
Derik
Posts: 1804
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Moon phase

Post by Derik » Wednesday 04 January 2017 20:43

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: 144
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi
Domoticz version: beta
Location: Stockholm / Sweden
Contact:

Re: Moon phase

Post by Minglarn » Saturday 21 January 2017 10:43

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: 134
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Moon phase

Post by bertbigb » Monday 24 April 2017 13:16

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 DS1515+ - DSM 6.1
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: 134
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Moon phase

Post by bertbigb » Sunday 14 May 2017 8:58

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 DS1515+ - DSM 6.1
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

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

Re: Moon phase

Post by Derik » Sunday 14 May 2017 9:11

@ 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: 95
Joined: Friday 13 November 2015 10:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Moon phase

Post by assenzuid » Wednesday 17 May 2017 12:17

Someone able to share the icon set and how to implement?
Moved recently to Emmen.

Hesmink
Posts: 153
Joined: Monday 22 June 2015 10:48
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: Moon phase

Post by Hesmink » Friday 02 June 2017 23:18

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"

Eddiever
Posts: 51
Joined: Thursday 27 April 2017 20:32
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: The Netherlands (Hoogeveen)
Contact:

Re: Moon phase

Post by Eddiever » Sunday 11 June 2017 13:15

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 847 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 )
RPi 2B with Domoticz and cam module RPi 3 with cam module
1 rftxtrx433E module 1 solar-edge SE-3500
1 Sonoff Touch 3 Sonoff wifi swithes 6 kaku modules

bertbigb
Posts: 134
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Moon phase

Post by bertbigb » Thursday 15 June 2017 16:11

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 DS1515+ - DSM 6.1
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: 95
Joined: Friday 13 November 2015 10:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Moon phase

Post by assenzuid » Thursday 15 June 2017 22:40

How to configure domoticz to show the correct icon(s)
Moved recently to Emmen.

Jan Jansen
Posts: 129
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Moon phase

Post by Jan Jansen » Tuesday 20 June 2017 19:42

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: 3
Joined: Tuesday 20 June 2017 20:01
Target OS: Linux
Domoticz version:
Contact:

Re: Moon phase

Post by natywna » Tuesday 20 June 2017 20:06

Nice work! In full moon I was always a little bit weird and slep not too good.

Eddiever
Posts: 51
Joined: Thursday 27 April 2017 20:32
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: The Netherlands (Hoogeveen)
Contact:

Re: Moon phase

Post by Eddiever » Tuesday 20 June 2017 20:53

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!
RPi 2B with Domoticz and cam module RPi 3 with cam module
1 rftxtrx433E module 1 solar-edge SE-3500
1 Sonoff Touch 3 Sonoff wifi swithes 6 kaku modules

jackslayter
Posts: 222
Joined: Tuesday 07 October 2014 11:00
Target OS: Raspberry Pi
Domoticz version: LastBeta
Location: France RA
Contact:

Re: Moon phase

Post by jackslayter » Tuesday 04 July 2017 10:17

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: 24
Joined: Wednesday 19 July 2017 19:50
Target OS: Raspberry Pi
Domoticz version: Beta
Location: US
Contact:

Re: Moon phase

Post by tottka » Tuesday 15 August 2017 14:17

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: 330
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Netherland
Contact:

Re: Moon phase

Post by htilburgs » Wednesday 13 September 2017 17:34

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:
Raspberry Pi 2B - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led

elmortero
Posts: 126
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 2.3852
Location: Spain
Contact:

Re: Moon phase

Post by elmortero » 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 --:--

User avatar
htilburgs
Posts: 330
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Netherland
Contact:

Re: Moon phase

Post by htilburgs » Wednesday 13 September 2017 20:45

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:
Raspberry Pi 2B - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led

User avatar
EdwinK
Posts: 715
Joined: Sunday 22 January 2017 22:46
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Rhoon - Netherlands
Contact:

Re: Moon phase

Post by EdwinK » Wednesday 13 September 2017 20:49

Thanks. Seems to work again


(Why don't we have a 'thanks' button in here?) ;)
Running latest STABLE on a NAS Synology 413j | Toon Thermostat | RFxcom | Dashticz V2 |

User avatar
htilburgs
Posts: 330
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Netherland
Contact:

Re: Moon phase

Post by htilburgs » Wednesday 13 September 2017 21:04

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 122 times
Hardware:
Raspberry Pi 2B - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests