MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    ShellyPV mit Shelly 2.5

    Scheduled Pinned Locked Moved Utilities
    16 Posts 3 Posters 1.7k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      chrisfr1976 @visionmaster
      last edited by

      @visionmaster
      Perfekt. Freut mich! Morgen probiere mich an der RGB Shelly. Kann es aber noch nicht versprechen. Wenn das läuft aktualisiere ich die Module für Table und PV bei Github.

      Regards, Chris.

      1 Reply Last reply Reply Quote 0
      • C Offline
        chrisfr1976 @visionmaster
        last edited by chrisfr1976

        @visionmaster
        Vielleicht einfacher als gedacht. Wieder als node_helper.js übernehmen:

        const NodeHelper = require("node_helper");
        const axios = require("axios");
        
        module.exports = NodeHelper.create({
            start: function () {
                this.config = {};
        
                setTimeout(() => {
                    console.log("MagicMirror is ready. Fetching ShellyPV status...");
                    this.fetchShellyPVStatus();
                }, 15000); // Delay to ensure MagicMirror is fully loaded
            },
        
            socketNotificationReceived: function (notification, payload) {
                if (notification === "CONFIG") {
                    this.config = payload;
        
                    if (this.config.shellysPV && Array.isArray(this.config.shellysPV)) {
                        console.log("Configuration received, fetching ShellyPV status...");
                        this.fetchShellyPVStatus();
                    }
                } else if (notification === "GET_SHELLYPV_STATUS") {
                    this.fetchShellyPVStatus();
                }
            },
        
            fetchShellyPVStatus: async function () {
                const results = [];
        
                if (!this.config.shellysPV || !Array.isArray(this.config.shellysPV)) {
                    console.error("No valid shellysPV configuration found or 'shellysPV' is not an array.");
                    return;
                }
        
                for (const shellyPV of this.config.shellysPV) {
                    try {
                        const response = await axios.post(
                            `${this.config.serverUri}/device/status`,
                            `id=${shellyPV.id}&auth_key=${this.config.authKey}`
                        );
        
                        const data = response.data?.data?.device_status;
        
                        if (data) {
                            let isOn = false;
                            let power = null;
        
                            // Check for Gen 1/2 structure (relay-based devices)
                            if (data.relays) {
                                const channel = parseInt(shellyPV.ch || 0, 10);
                                isOn = data.relays[channel]?.ison || false;
                                power = data.meters?.[channel]?.power || null;
                            }
                            // Check for Gen 3 structure (pm1:0 devices)
                            else if (data["pm1:0"]) {
                                isOn = true; // Assume true if data exists for the device
                                power = data["pm1:0"].apower; // Use 'apower' from pm1:0
                            }
                            // Check for "switch:0" structure
                            else if (data["switch:0"]) {
                                isOn = data["switch:0"].output; // Use 'output' for on/off status
                                power = data["switch:0"].apower; // Use 'apower' for power
                            }
                            // Check for RGB Shelly structure (lights array)
                            else if (data.lights) {
                                const light = data.lights[0]; // Assume single channel for RGB device
                                isOn = light?.ison || false;
                                power = light?.power || null;
                            }
        
                            results.push({
                                name: shellyPV.name,
                                isOn: isOn,
                                power: power !== undefined ? power : null,
                                statusClass: isOn ? 'on' : 'off', // Dynamically set status class
                            });
                        } else {
                            results.push({
                                name: shellyPV.name,
                                isOn: false,
                                power: null,
                                statusClass: 'off', // Default to off if no data found
                            });
                        }
                    } catch (error) {
                        console.error(`Error fetching status for ${shellyPV.name}:`, error);
                        results.push({
                            name: shellyPV.name,
                            isOn: false,
                            power: null,
                            statusClass: 'off', // Default to off on error
                        });
                    }
                }
        
                this.sendSocketNotification("SHELLYPV_STATUS_UPDATE", results);
            },
        });
        
        

        In der config wieder wie üblich einrichten.

        Regards, Chris.

        V 1 Reply Last reply Reply Quote 0
        • V Offline
          visionmaster @chrisfr1976
          last edited by

          @chrisfr1976
          Hi und wiedermal Danke.
          Funktioiert fast :)
          Status On/Off funktioniert
          Power teilweise. Wenn Status an: korrekt Anzeige. Wenn Status Off: Anzeige > N/A. Manchmal bleibt sogar die Poweranzeige auf den letzten Wert, obwohl die Shelly ausgeschaltet ist.

          "lights":[{"ison":true,"source":"http","has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"mode":"color","red":0,"green":0,"blue":255,"white":0,"gain":79,"effect":0,"transition":0,"power":3.59,"overpower":false,"brightness":79}]
          

          d816e5a2-4007-481f-8298-50c0f41bffb9-grafik.png

          V 1 Reply Last reply Reply Quote 0
          • V Offline
            visionmaster @visionmaster
            last edited by

            @visionmaster
            Hier zur Info:

            Ich habe :

            else if (data.lights) {
            const light = data.lights[0]; // Assume single channel for RGB device
            isOn = light?.ison || false;
            power = light?.power || null;
            }

            durch:

            else if (data.lights) {
            const light = data.lights[0]; // Assume single channel for RGB device
            isOn = light?.ison || false;
            power = data.meters ? data.meters[0].power : null;
            }

            ersetzt. Jetzt zeigt er alles richtig an. :)

            C 1 Reply Last reply Reply Quote 1
            • C Offline
              chrisfr1976 @visionmaster
              last edited by

              @visionmaster Danke für die Antwort. Die Module sind in GitHub aktualisiert.

              So, issue closed until new devices pop up ;-)

              Regards, Chris.

              1 Reply Last reply Reply Quote 0
              • 1
              • 2
              • 1 / 2
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy