• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.5k 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.
  • V Offline
    visionmaster
    last edited by Nov 25, 2024, 7:31 PM

    Hi,
    ich habe einen Shelly 2.5 Dieser hat 2 Schaltausgänge. Der Shelly hat aber nur eine ID. Daher kann ich immer nur Gerätekanal 0 abfragen. Wie komme ich an den Zustand von Gerätekanal 1 ran ? Ich bekomme also immer nur den Status einer Lampe ( an/aus).
    Kann man über die API 2 Kanäle abfragen?
    RGBW2 ( LED Kontroller) geht leider auch garnicht.

    C 1 Reply Last reply Nov 25, 2024, 9:21 PM Reply Quote 0
    • C Offline
      chrisfr1976 @visionmaster
      last edited by chrisfr1976 Nov 25, 2024, 9:23 PM Nov 25, 2024, 9:21 PM

      @visionmaster Hi, sehe ich mir an. Solche Geräte habe ich im Moment noch nicht im Einsatz. Schicke in der Console mal diesen Befehl an die entsprechende Shelly und poste mir die Antwort:

      curl -X POST https://<server_uri>/device/status -d "id=<device_id>&auth_key=<auth_key>"
      

      In der Antwort Deinen Auth-key löschen!

      Vielleicht werden hier mehrere Infos zurückgeschickt.

      Regards, Chris.

      V 2 Replies Last reply Nov 26, 2024, 7:03 PM Reply Quote 0
      • V Offline
        visionmaster @chrisfr1976
        last edited by sdetweil Nov 26, 2024, 7:17 PM Nov 26, 2024, 7:03 PM

        @chrisfr1976
        Hi, und Danke für die schnelle Antwort.
        Hier kommt das “Ergebnis”:

        {
          "isok": true,
          "data": {
            "online": true,
            "device_status": {
              "ram_free": 38212,
              "serial": 37812,
              "_updated": "2024-11-26 18:42:40",
              "relays": [
                {
                  "ison": false,
                  "has_timer": false,
                  "timer_started": 0,
                  "timer_duration": 0,
                  "timer_remaining": 0,
                  "overpower": false,
                  "overtemperature": false,
                  "is_valid": true,
                  "source": "cloud"
                },
                {
                  "ison": false,
                  "has_timer": false,
                  "timer_started": 0,
                  "timer_duration": 0,
                  "timer_remaining": 0,
                  "overpower": false,
                  "overtemperature": false,
                  "is_valid": true,
                  "source": "cloud"
                }
              ],
              "inputs": [
                {
                  "input": 0,
                  "event": "",
                  "event_cnt": 0
                },
                {
                  "input": 0,
                  "event": "",
                  "event_cnt": 0
                }
              ],
              "unixtime": 1732639886,
              "cloud": {
                "enabled": true,
                "connected": true
              },
              "time": "17:51",
              "meters": [
                {
                  "power": 0,
                  "overpower": 0,
                  "is_valid": true,
                  "timestamp": 1732650160,
                  "counters": [
                    0,
                    0,
                    0
                  ],
                  "total": 3558
                },
                {
                  "power": 0,
                  "overpower": 0,
                  "is_valid": true,
                  "timestamp": 1732650160,
                  "counters": [
                    0,
                    0,
                    0
                  ],
                  "total": 22099
                }
              ],
              "ram_total": 50720,
              "temperature_status": "Normal",
              "wifi_sta": {
                "connected": true,
                "ssid": "###########",
                "ip": "192.168.178.28",
                "rssi": -90
              },
              "voltage": 234.61,
              "fs_free": 146082,
              "has_update": false,
              "cfg_changed_cnt": 0,
              "overtemperature": false,
              "actions_stats": {
                "skipped": 0
              },
              "uptime": 1755490,
              "temperature": 59.87,
              "tmp": {
                "tC": 59.87,
                "tF": 139.77,
                "is_valid": true
              },
              "mac": "############",
              "fs_size": 233681,
              "getinfo": {
                "fw_info": {
                  "device": "shellyswitch25-#############",
                  "fw": "20230913-112234/v1.14.0-gcb84623"
                }
              },
              "mqtt": {
                "connected": false
              },
              "update": {
                "status": "idle",
                "has_update": false,
                "new_version": "20230913-112234/v1.14.0-gcb84623",
                "old_version": "20230913-112234/v1.14.0-gcb84623",
                "beta_version": "20231107-163214/v1.14.1-rc1-g0617c15"
              }
            }
          }
        }
        

        Über die Shelly App sehe ich unter Geräteinformationen bei der 1. “Lampe” ein Gerätekanal 0 und bei der 2. “Lampe” steht halt Gerätekanal 1. Beide haben die selbe Geräte-ID

        moderator: edited to add code block and formatted json

        V 2 Replies Last reply Nov 26, 2024, 7:25 PM Reply Quote 0
        • V Offline
          visionmaster @visionmaster
          last edited by Nov 26, 2024, 7:25 PM

          @visionmaster

          Den einzigen Unterschied sehe ich hier:
          Beide Lampen aus:
          “relays”:[{“ison”:false,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”},{“ison”:false,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”}]
          Kanal 0 an:
          “relays”:[{“ison”:true,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”},{“ison”:false,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”}]
          Kanal 1 an:
          “relays”:[{“ison”:false,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”},{“ison”:true,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”}]
          Beide Kanäle an:
          “relays”:[{“ison”:true,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”},{“ison”:true,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”}]

          Ich sehe zwar, das sich bei ison: true / false was ändert, aber da steht nichts von Kanäle.

          1 Reply Last reply Reply Quote 0
          • V Offline
            visionmaster @visionmaster
            last edited by Nov 26, 2024, 7:32 PM

            @visionmaster
            Also ich sehe im Vergleich zu einem anderen Shelly mit nur einem Kanal, daß im Block “relays” nur 1 “Block” existiert, während es beim Shelly 2.5 > 2 Blöcke sind.
            Einfacher shelly:
            “relays”:[{“ison”:false,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“source”:“cloud”}]
            Shelly mit 2 Ausgängen:
            “relays”:[{“ison”:false,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”},{“ison”:true,“has_timer”:false,“timer_started”:0,“timer_duration”:0,“timer_remaining”:0,“overpower”:false,“overtemperature”:false,“is_valid”:true,“source”:“http”}]

            Vielleicht muss man die Abfrage “erweitern”

            1 Reply Last reply Reply Quote 0
            • V Offline
              visionmaster @chrisfr1976
              last edited by Nov 26, 2024, 7:35 PM

              Vielleicht kann ja die Config erweitert werden:

              shellys: [
              { name: “Küche Hauptlicht”, id: “#####”,Kanal:“0” },
              { name: “Küche Unterschrank”, id: “####” ,Kanal:“1”},
              ],
              Und natürlich das Script :)

              V 1 Reply Last reply Nov 26, 2024, 7:54 PM Reply Quote 0
              • V Offline
                visionmaster @visionmaster
                last edited by Nov 26, 2024, 7:54 PM

                @visionmaster

                Und hier noch eine Info:
                Bei einem shellyrgbw2 heißt das Zauberwort “lights”
                Vielleicht könnte man da ja auch den OnOff Status abfragen

                “lights”:[{“ison”:false,“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”:0,“overpower”:false,“brightness”:79}]

                Komplett:
                {“isok”:true,“data”:{“online”:true,“device_status”:{“ram_free”:39280,“serial”:27538,“_updated”:“2024-11-26 19:42:59”,“inputs”:[{“input”:0,“event”:“”,“event_cnt”:0}],“unixtime”:1732650104,“cloud”:{“enabled”:true,“connected”:true},“time”:“20:42”,“meters”:[{“power”:0,“is_valid”:true,“overpower”:false,“timestamp”:1732653779,“counters”:[0.893,0,0],“total”:1341}],“ram_total”:51672,“mode”:“color”,“wifi_sta”:{“connected”:true,“ssid”:“#####”,“ip”:“192.168.178.27”,“rssi”:-73},“fs_free”:151353,“has_update”:false,“cfg_changed_cnt”:1,“actions_stats”:{“skipped”:0},“uptime”:7212089,“mac”:“#####”,“fs_size”:233681,“getinfo”:{“fw_info”:{“device”:“shellyrgbw2-#####”,“fw”:“20230913-113259/v1.14.0-gcb84623”,“mode”:“color”}},“mqtt”:{“connected”:false},“update”:{“status”:“idle”,“has_update”:false,“new_version”:“20230913-113259/v1.14.0-gcb84623”,“old_version”:“20230913-113259/v1.14.0-gcb84623”,“beta_version”:“20231107-164040/v1.14.1-rc1-g0617c15”},“input”:0,“lights”:[{“ison”:false,“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”:0,“overpower”:false,“brightness”:79}]

                S C 3 Replies Last reply Nov 26, 2024, 8:00 PM Reply Quote 0
                • S Offline
                  sdetweil @visionmaster
                  last edited by Nov 26, 2024, 8:00 PM

                  @visionmaster both, please try to use code blocks around data like this and config and logs

                  paste the text into the message editor
                  select the text
                  hit the </> button in the editor bar

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    chrisfr1976 @visionmaster
                    last edited by Nov 26, 2024, 9:17 PM

                    @visionmaster Hi, werde es mir morgen anschauen. Danke für die Infos.

                    Regards, Chris.

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      chrisfr1976 @visionmaster
                      last edited by Nov 27, 2024, 5:21 PM

                      @visionmaster

                      Hi,

                      please replace the node_helper.js in the module MMM-ShellyPV with the following code. If you receive an error, please describe what you see or what error messages you get. Since I do not have such a device yet it is not possible for me to test it.

                      At first I start with the Shelly 2.5 device. The “shellyrgbw2” is then the next step!

                      The config must be like this for these specific 2.5 devices:

                      shellysPV: [
                          { name: "Kueche 1", id: "dcda0cb93bb8", ch: "1" }, // Channel 1 (relay[0])
                          { name: "Kueche 2", id: "dcda0cb93bb8", ch: "2" }  // Channel 2 (relay[1])
                      ]
                      

                      I’ve used 1 and 2 instead of 0 and 1. It is easier for my head :-)

                      And next the updated node_helper.js file:

                      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;
                      
                                          // Handle multi-channel devices
                                          if (data.relays && shellyPV.ch) {
                                              const channelIndex = parseInt(shellyPV.ch, 10) - 1; // Convert to zero-based index
                                              if (channelIndex >= 0 && channelIndex < data.relays.length) {
                                                  const relay = data.relays[channelIndex];
                                                  const meter = data.meters?.[channelIndex];
                      
                                                  isOn = relay.ison;
                                                  power = meter?.power || 0;
                                              } else {
                                                  console.error(`Invalid channel index for ${shellyPV.name}: ${shellyPV.ch}`);
                                              }
                                          }
                                          // Handle single-channel devices (or default behavior for Gen 1/2)
                                          else if (data.relays) {
                                              isOn = data.relays[0].ison;
                                              power = data.meters ? data.meters[0].power : null;
                                          }
                                          // Handle Gen 3 devices (pm1:0 structure)
                                          else if (data["pm1:0"]) {
                                              isOn = true; // Assume true if data exists
                                              power = data["pm1:0"].apower;
                                          }
                                          // Handle switch:0 structure
                                          else if (data["switch:0"]) {
                                              isOn = data["switch:0"].output;
                                              power = data["switch:0"].apower;
                                          }
                      
                                          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);
                          },
                      });
                      
                      

                      For devices without a ch parameter, the logic defaults to using the first relay and meter (relays[0], meters[0]), ensuring compatibility with single-channel or older devices.
                      If a ch parameter is specified in the config, the code now accesses the corresponding relays and meters arrays for the specific channel.

                      Regards, Chris.

                      V 1 Reply Last reply Nov 27, 2024, 9:43 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        4/16
                        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