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.

    Problem with MMM-ValuesByNotification and MMM-CommandToNotification

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    19 Posts 3 Posters 2.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.
    • J Offline
      Jimmy1502
      last edited by sdetweil

      Hello i used to following code to add a temperature and humitidy display to my magic mirror. i use a dht22 and i already checked the sensor with a arduino. it is working and giving reasonable outputs. But i just get “Timeout” or “0.00” as values. So did i mess up the code?

      {
         			module: "MMM-CommandToNotification",
      			disabled: false,
         			config: {
      				updateInterval: 10,
          				commands: [
          					{
          					script: "./dht22",
      					timeout: 55,
      					args: "12",
      					notifications: [
      					"Tempout"
             						]
      					}
      
      					]
         				},
        		},
      		        {
                  		module: "MMM-ValuesByNotification",
                  		position: "bottom_left",
                  		header: "Diele",
                  		config: {
                      		updateInterval: 10,
                      		reuseCount: 100,
                      		groups: [
                          			{
                              		items: [
                                  			{
                                      		notification: "Tempout",
                                      		itemTitle: "Bathroom",
                                      		values: [
                                          		{
                                              valueIcon: "fa fa-thermometer-full",
                                              valueUnit: "°C",
                                              valueFormat: "Number(${value}).toFixed(2)",
                                              jsonpath: "temperature",
                                              thresholds: [
                                                  {
                                                      value: "15",
                                                      type: "lt",
                                                      classes: "lt15"
                                                  },
                                                  {
                                                      value: "20",
                                                      type: "lt",
                                                      classes: "lt20"
                                                  },
                                              ]
                                          },
                                          {
                                              valueIcon: "fa fa-tint",
                                              valueUnit: "%rH",
                                              valueFormat: "Number(${value}).toFixed(1)",
                                              jsonpath: "humidity",
                                          },
                                      ]
                                  },
                              ]
                          },
                      ]
                  },
              },
      
      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @Jimmy1502
        last edited by

        @Jimmy1502 said in Problem with MMM-ValuesByNotification and MMM-CommandToNotification:

        script: “./dht22”,

        where is that file?

        when MagicMirror is running the current directory is ~/MagicMirror…
        NOT any module folder…

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          Jimmy1502 @sdetweil
          last edited by sdetweil

          @sdetweil Hi thx for the fast reply. This is a script from the creator of the module. In the module folder is another folder with scripts. The description how to use it is:

          script: Either a absolute path or the realtive path of a script starting at the “scripts” directory. Make sure to add a “./” as prefix if you call a script in the “scripts” directory.

          And in his example he did this:

            {
             module: "MMM-CommandToNotification",
             disabled: false,
             config: {
              updateInterval: 10,
              commands: [
               {
                script: "./randomInteger.js",
                args: "-10 10",
                timeout: 5,
                notifications: [
                 "TEST1",
                 "TEST2",
                ],
               },
               {
                script: "./randomNumberJson.js",
                args: "-50 20",
                skips: 3,
                timeout: 10,
                conditions: {
                  returnCode: [0,1,2]
                }
                notifications: [
                 "TEST3",
                 ["TEST4", true]
                ],
               }
              ]
             },
            },
          

          I changed it to:
          script: “./temperature/dht22”,

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @Jimmy1502
            last edited by

            @Jimmy1502 said in Problem with MMM-ValuesByNotification and MMM-CommandToNotification:

            script: “./temperature/dht22”,

            and did that help??

            notice that I edited your posts to put code wrapper around the config.js info

            please do this in the future

            paste your text into the editor
            blank line above and below

            select the text you just pasted,m and then hit the </> button to add the code wrapper.

            the code wrapper keeps formatting and makes it easier to read

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              Jimmy1502 @sdetweil
              last edited by

              @sdetweil No sadly not, still getting “timeout”. I try to implement the codewrapper. Im new to this sry.

              S wishmaster270W 2 Replies Last reply Reply Quote 0
              • S Offline
                sdetweil @Jimmy1502
                last edited by

                @Jimmy1502 said in Problem with MMM-ValuesByNotification and MMM-CommandToNotification:

                I try to implement the codewrapper. Im new to this sry.

                np, we all learn about it…

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • wishmaster270W Online
                  wishmaster270 Module Developer @Jimmy1502
                  last edited by

                  @Jimmy1502 Hi and thanks to @sdetweil for trying to help.

                  I will try to update the readme of the module in the next days.

                  The timeout is set in milliseconds. Your config looks like it is set to 5ms. The script will not be able to respond in this time.
                  Please increase it to a value much higher especially for the dht sensor. Let’s say something like 1000ms.

                  J 1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jimmy1502 @wishmaster270
                    last edited by

                    @wishmaster270 Hi! This explains the “Timeout” and i changed it. But now i just gut “0.00” as values. Do i have other mistakes in the code? Can i use all GPIO Pins or just special ones? I tried 18,21,25.

                    wishmaster270W 1 Reply Last reply Reply Quote 0
                    • wishmaster270W Online
                      wishmaster270 Module Developer @Jimmy1502
                      last edited by wishmaster270

                      @Jimmy1502
                      The script uses GPIO 4 in default but accepts any GPIO number as first argument.
                      At least GPIO 25 has no double function on raspberries and should work.

                      You can call the script directly in the shell and check the output for debug purposes.
                      And make sure to check the comments in the first lines of the script if you need to. install any dependencies.

                      Edit: Looks like you use GPIO 12 in your config which should work, too

                      J 2 Replies Last reply Reply Quote 0
                      • J Offline
                        Jimmy1502 @wishmaster270
                        last edited by

                        @wishmaster270 this advice really helped. I tried using the script and saw, that the adafruit library was outdated. Updated it and now it kinda works. The script and my sensor is working. I get good reasonable values if i use the script manually. But the Mirror is kinda weird.
                        When i measured the temperature manually it said sth. around 21°C but ValuesByNotification outputs: “NaN” so Not a Number?
                        Humidity is kinda working. The majority of the time it is giving me a value of 47%rH but sometimes after the module is blinking (I think it is refreshing), it suddenly changes to 0.00%rH. But the next blink changes it back to a real value.

                        Thx for your help

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jimmy1502 @wishmaster270
                          last edited by

                          @wishmaster270 Oh i could sworn i just submitted sth. but i cant see it in the notifications…

                          Well for a second time:

                          It kinda works now. I tried using the script as u said manually and the dependencies (adafruit library) wasnt up to date. I got reasonable outputs.
                          But the ValuesByNotification Module isnt working as intended. I Just get a “NaN” (“not a number”?) for the temperature. The Humidity is kinda working giving me a reasonable output. But sometimes after a blink (i think a refresh?), the value changes to “0.00%rH” but after another one it is good again.

                          S wishmaster270W 2 Replies Last reply Reply Quote 0
                          • S Offline
                            sdetweil @Jimmy1502
                            last edited by sdetweil

                            @Jimmy1502 all.posts for users with reputation below 2 are reviewed by me before posting.

                            so… sometimes you have to wait til i get back to the forum

                            you can see your pendkngmpodts.in tye pending queue under your user icon top right

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            J 1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jimmy1502 @sdetweil
                              last edited by

                              @sdetweil i have seen thath. But usually it shows me in the notifications that its not approved yet. But i couldnt find it. Thats why i was confused.

                              S 1 Reply Last reply Reply Quote 0
                              • S Offline
                                sdetweil @Jimmy1502
                                last edited by

                                @Jimmy1502 I have seen the pending g list be empty when it’s not. maybe your side has the same problem

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                J 1 Reply Last reply Reply Quote 0
                                • wishmaster270W Online
                                  wishmaster270 Module Developer @Jimmy1502
                                  last edited by

                                  @Jimmy1502 I think the problem with the temperature is caused by the json path. The script outputs temperature_c and temperature_f but the json path causes the module to search for temperature only.

                                  The problem with the humidity may be caused by the interval you query the sponsor values. 10 seconds is very short for the dht sensor. Maybe you can try a bigger interval.

                                  1 Reply Last reply Reply Quote 0
                                  • J Offline
                                    Jimmy1502 @sdetweil
                                    last edited by

                                    @wishmaster270 I can see the temps now. I increased the UpdateInterval in both ValuesByNotification and CommandToNotification and made them different. But i still got the “0.00” for both temperature and humidity. But i dont think it should be the UpdateInterval. Cause when i tested the DHT22 with a Microcontroller i was able to get values every second.

                                    wishmaster270W 1 Reply Last reply Reply Quote 0
                                    • wishmaster270W Online
                                      wishmaster270 Module Developer @Jimmy1502
                                      last edited by wishmaster270

                                      @Jimmy1502 As the reuseCount is set to 100 the wrong value need to be caused by the script sending them.
                                      It only sends 0.0 if a error occurs.

                                      You may remove the except block in the script and fire it very quickly on the shell to see what causes the error.

                                      J 1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        Jimmy1502 @wishmaster270
                                        last edited by

                                        @wishmaster270
                                        Hi! Ive been busy so i couldnt work on it. I removed the except block with five “#” for each line to make it a comment. And i get the following error. The line 32 has a syntax error “invalid syntax”. It is the print function printing json.dumps(result))

                                        wishmaster270W 1 Reply Last reply Reply Quote 0
                                        • wishmaster270W Online
                                          wishmaster270 Module Developer @Jimmy1502
                                          last edited by

                                          @Jimmy1502
                                          You will need to comment the try, too. Additionally the indention of the code needs to be changed.
                                          The file will be look like this then:

                                          #!/bin/python3
                                          #Install Dependencies:
                                          #  pip3 install adafruit-circuitpython-dht
                                          #  sudo apt-get install libgpiod2
                                          import time
                                          import board
                                          import adafruit_dht
                                          import json
                                          import sys
                                          
                                          gpio_nr = 4
                                          if len(sys.argv) > 1:
                                              gpio_nr = int(sys.argv[1])
                                          
                                          
                                          # Initial the dht device, with data pin connected to:
                                          dhtDevice = adafruit_dht.DHT22(getattr(board, "D%d"%gpio_nr))
                                          
                                          result = {}
                                          result["temperature_c"] = dhtDevice.temperature
                                          result["humidity"] = dhtDevice.humidity
                                          result["temperature_f"] = (result["temperature_c"]*1.8) + 32
                                          result["error"] = False
                                          
                                          print(json.dumps(result))
                                          
                                          1 Reply Last reply Reply Quote 0

                                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                          With your input, this post could be even better 💗

                                          Register Login
                                          • 1 / 1
                                          • 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