Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Script für Mondphase

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Script für Mondphase

    This topic has been deleted. Only users with topic management privileges can see it.
    • Berges01
      Berges01 last edited by

      @paul53
      Du hast mal ein Script erstellt für die Mondphase.

      
      const suncalc = require('suncalc');
      const idVis = 'Vis.Mondphase';  // Für Vis
       
      createState(idVis, 0, {
         type: 'number',
         min: 0,
         max: 7,
         role: 'level',
         states: {
            0: 'Neumond',
            1: 'Viertelmond zu',
            2: 'Halbmond zu',
            3: 'Dreiviertelmond zu',
            4: 'Vollmond',
            5: 'Dreiviertelmond ab',
            6: 'Halbmond ab',
            7: 'Viertelmond ab'
         }   
      });
       
      function mpVis() {
         var mond = suncalc.getMoonIllumination(new Date());
         var mp = mond.phase;
         var state = 0; 
         if(mp > 0.05) state = 1;
         if(mp > 0.2) state = 2;
         if(mp > 0.3) state = 3;
         if(mp > 0.45) state = 4;
         if(mp > 0.55) state = 5;
         if(mp > 0.7) state = 6;
         if(mp > 0.8) state = 7;
         if(mp > 0.95) state = 0;
         setState(idVis, state, true);
      }
       
      mpVis(); // Skriptstart
       
      schedule("*/10 * * * *", mpVis);  // alle 10 Minuten
      
      

      So weit ich erkennen kann, ist das fast das was ich benötige.
      Leider habe ich keine Erfahrung in Java.
      Kann man das so umschrieben, das 2 Datenpunkte Mond_State und Mond_Text bei den Anderen Astrodaten beschrieben werden?

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Berges01 last edited by paul53

        @berges01 sagte: 2 Datenpunkte Mond_State und Mond_Text bei den Anderen Astrodaten

        const suncalc = require('suncalc');
        const idState = 'variables.astro.moonState';  // Für Vis
        const idText  = 'variables.astro.moonText';
        const states = {
            0: 'Neumond',
            1: 'Viertelmond zu',
            2: 'Halbmond zu',
            3: 'Dreiviertelmond zu',
            4: 'Vollmond',
            5: 'Dreiviertelmond ab',
            6: 'Halbmond ab',
            7: 'Viertelmond ab'
        };
         
        createState(idState, 0, {
           name: 'Mond Status', 
           type: 'number',
           min: 0,
           max: 7,
           role: 'value',
           read: true,
           write: false,
           states: states  
        });
        createState(idText, '', {
            name: 'Mond Text',
            type: 'string',
            role: 'text', 
            read: true,
            write: false
        });
         
        function mpVis() {
           const mond = suncalc.getMoonIllumination(new Date());
           const mp = mond.phase;
           let state = 0; 
           if(mp > 0.05) state = 1;
           if(mp > 0.2) state = 2;
           if(mp > 0.3) state = 3;
           if(mp > 0.45) state = 4;
           if(mp > 0.55) state = 5;
           if(mp > 0.7) state = 6;
           if(mp > 0.8) state = 7;
           if(mp > 0.95) state = 0;
           setState(idState, state, true);
           setState(idText, states[state], true);
        }
         
        setTimeout(mpVis, 200); // Skriptstart
         
        schedule("*/10 * * * *", mpVis);  // alle 10 Minuten
        
        Berges01 1 Reply Last reply Reply Quote 0
        • Berges01
          Berges01 @paul53 last edited by

          @paul53
          Besten Dank !
          Das funktioniert Gut, jetzt kann ich weiter machen und habe eine Vorlage.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          706
          Online

          31.7k
          Users

          79.7k
          Topics

          1.3m
          Posts

          2
          3
          167
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo