• 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.

JSON request module

Scheduled Pinned Locked Moved Solved Requests
41 Posts 3 Posters 12.4k Views 4 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.
  • W Offline
    wishmaster270 Module Developer @ELMAGO
    last edited by Dec 7, 2022, 7:37 PM

    @ELMAGO Sorry, but i do not understand exactly what you mean. You can override the “na” value which is the one displayed if no value could be parsed in the JSON.

    The config option is:

    naValue: "NON"
    

    There might also be a chance to do add a valueFormat which checks for the “false” value in the JSON but that would be a little more complex and i need to know the exact format of the output.

    E 1 Reply Last reply Dec 8, 2022, 6:24 AM Reply Quote 0
    • E Offline
      ELMAGO @wishmaster270
      last edited by Dec 8, 2022, 6:24 AM

      @wishmaster270
      Hello

      No, not al all.
      the returned value will be “false” or “true” and I would like to replace it with “Non” or “Oui” in French.

      W 1 Reply Last reply Dec 8, 2022, 3:57 PM Reply Quote 0
      • W Offline
        wishmaster270 Module Developer @ELMAGO
        last edited by Dec 8, 2022, 3:57 PM

        @ELMAGO
        You can use valueFormat for this purpose.

        valueFormat: "\"${value}\".replace(\"false\",\"Non\").replace(\"true\",\"Oui\")",
        

        This will convert the value to a string (if needed) and replaces all “false” with “Non” and “true” with “Oui”.

        E 1 Reply Last reply Dec 8, 2022, 7:34 PM Reply Quote 0
        • E Offline
          ELMAGO @wishmaster270
          last edited by Dec 8, 2022, 7:34 PM

          @wishmaster270

          great, thank you.
          Is there a “lexicon” with these commands?

          W 1 Reply Last reply Dec 9, 2022, 2:10 PM Reply Quote 0
          • W Offline
            wishmaster270 Module Developer @ELMAGO
            last edited by Dec 9, 2022, 2:10 PM

            @ELMAGO
            I added some to the [documentation] (https://github.com/Tom-Hirschberger/MMM-ValuesByNotification/blob/main/doc/value.md) of the module.
            As there can be used any build-in JavaScript function in valueFormat there are nearly endless possibilities.

            E 1 Reply Last reply Dec 11, 2022, 6:36 PM Reply Quote 0
            • E Offline
              ELMAGO @wishmaster270
              last edited by Dec 11, 2022, 6:36 PM

              @wishmaster270

              good evening,

              I tested the replace function:

              {
              		module: "MMM-ValuesByNotification",
              		position: "top_right",
              		header: "INFORMATION MÉGANE",
              		config: {
              			updateInterval: 300,
              			reuseCount: 100,
              			addClassesRecursive: true,
              			valueFormat: "\"${value}\".replace(\"false\",\"Non\").replace(\"true\",\"Oui\")",
              			groups: [
              				{
              					items: [
              						
              						{
              							notification: "AUTBATTMEGANE",
              							itemTitle: "Autonomie  ",
              							values: [
              								{
              									valueUnit: " Km",
              									valueFormat: "Number(${value}).toFixed(2)",
              									jsonpath: "data",
              								},
              							]
              						},
              						{
              							notification: "BATTMEGANE",
              							itemTitle: "Charge batterie  ",
              							values: [
              								{
              									valueUnit: " %",
              									valueFormat: "Number(${value}).toFixed(2)",
              									jsonpath: "data",
              								},
              							]
              						},
              						{
              							notification: "PLUGMEGANE",
              							itemTitle: "Voirture branchée ",
              							classes: "withIcons",
              							valueFormat: "\"${value}\".replace(\"false\",\"Non\").replace(\"true\",\"Oui\")",
              							values: [
              								{
              									
              									valueFormat: "Number(${value}).toFixed(2)",
              									jsonpath: "data",
              								},
              							]
              						},
              						
              					]
              				},
              			]
              		},
              	},
              
              
              

              But unfortunately it doesn’t work.

              504f3bb6-cb32-49fa-97b6-c872e2b1aa31-image.png

              Would you know why?

              Thanks

              W 1 Reply Last reply Dec 11, 2022, 6:51 PM Reply Quote 0
              • W Offline
                wishmaster270 Module Developer @ELMAGO
                last edited by Dec 11, 2022, 6:51 PM

                @ELMAGO As valueFormat settings further down in the hierarchy override setting further up you only have to much valueFormat settings.

                This config should do the trick:

                	{
                		module: "MMM-ValuesByNotification",
                		position: "top_right",
                		header: "INFORMATION MÉGANE",
                		config: {
                			updateInterval: 300,
                			reuseCount: 100,
                			addClassesRecursive: true,
                			groups: [
                				{
                					items: [
                						
                						{
                							notification: "AUTBATTMEGANE",
                							itemTitle: "Autonomie  ",
                							values: [
                								{
                									valueUnit: " Km",
                									valueFormat: "Number(${value}).toFixed(2)",
                									jsonpath: "data",
                								},
                							]
                						},
                						{
                							notification: "BATTMEGANE",
                							itemTitle: "Charge batterie  ",
                							values: [
                								{
                									valueUnit: " %",
                									valueFormat: "Number(${value}).toFixed(2)",
                									jsonpath: "data",
                								},
                							]
                						},
                						{
                							notification: "PLUGMEGANE",
                							itemTitle: "Voirture branchée ",
                							classes: "withIcons",
                							values: [
                								{
                									valueFormat: "\"${value}\".replace(\"false\",\"Non\").replace(\"true\",\"Oui\")",
                									jsonpath: "data",
                								},
                							]
                						},
                						
                					]
                				},
                			]
                		},
                	},
                
                1 Reply Last reply Reply Quote 0
                • E Offline
                  ELMAGO
                  last edited by Jan 23, 2023, 7:36 PM

                  Hi @wishmaster270

                  I come back here, it will be simpler.

                  My code is:

                  //INFORMATION HOMEY EUFY
                  
                  {
                     module: "MMM-CommandToNotification",
                     disabled: false,
                     config: {
                      updateInterval: 300,
                      commands: [
                       
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/ETATEUFY",
                             timeout: 1000,
                  			
                             notifications: [
                              "ETATEUFY",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMSALLE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMSALLE",
                              ],
                            },
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMPALIER",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMPALIER",
                              ],
                            },
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMARRIERE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMARRIERE",
                              ],
                            },
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMGARAGE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMGARAGE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMGAUCHE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMGAUCHE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMAVANT",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMAVANT",
                              ],
                            },
                  {
                        script: "/usr/bin/curl",
                        args: "-s  http://192.168.100.244:3000/TEMPSALLE",
                        timeout: 1000,
                        notifications: [
                         "TEMPSALLE",
                         ],
                       },
                  
                       {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPBUREAU",
                             timeout: 1000,
                             notifications: [
                              "TEMPBUREAU",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHELENA",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHELENA",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHLOUCA",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHLOUCA",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHALAN",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHALAN",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHPARENT",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHPARENT",
                              ],
                            },
                  {
                        	script: "/usr/bin/curl",
                        	args: "-s  http://192.168.100.244:3000/AUTBATTMEGANE",
                        	timeout: 1000,
                        	notifications: [
                         	"AUTBATTMEGANE",
                         	  ],
                       		},
                  
                       {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/BATTMEGANE",
                             timeout: 1000,
                             notifications: [
                              "BATTMEGANE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/PLUGMEGANE",
                             timeout: 1000,
                  			
                             notifications: [
                              "PLUGMEGANE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CHARGEMEGANE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CHARGEMEGANE",
                              ],
                            },
                  
                       ]
                     },
                    },
                  

                  So I think it launches all requests at the same time, because my server which must answer crashes.

                  I wanted to split it like this:

                  //INFORMATION HOMEY EUFY
                  
                  {
                     module: "MMM-CommandToNotification",
                     disabled: false,
                     config: {
                      updateInterval: 300,
                      commands: [
                       
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/ETATEUFY",
                             timeout: 1000,
                  			
                             notifications: [
                              "ETATEUFY",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMSALLE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMSALLE",
                              ],
                            },
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMPALIER",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMPALIER",
                              ],
                            },
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMARRIERE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMARRIERE",
                              ],
                            },
                  
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMGARAGE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMGARAGE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMGAUCHE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMGAUCHE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CAMAVANT",
                             timeout: 1000,
                  			
                             notifications: [
                              "CAMAVANT",
                              ],
                            },
                       ]
                     },
                    },
                  
                  
                  

                  and

                  //INFORMATION HOMEY EUFY
                  
                  {
                     module: "MMM-CommandToNotification",
                     disabled: false,
                     config: {
                      updateInterval: 300,
                      commands: [
                       
                  
                  
                  {
                        script: "/usr/bin/curl",
                        args: "-s  http://192.168.100.244:3000/TEMPSALLE",
                        timeout: 1000,
                        notifications: [
                         "TEMPSALLE",
                         ],
                       },
                  
                       {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPBUREAU",
                             timeout: 1000,
                             notifications: [
                              "TEMPBUREAU",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHELENA",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHELENA",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHLOUCA",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHLOUCA",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHALAN",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHALAN",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/TEMPCHPARENT",
                             timeout: 1000,
                             notifications: [
                              "TEMPCHPARENT",
                              ],
                            },
                  
                  
                       ]
                     },
                    },
                  
                  
                  

                  and :

                  //INFORMATION HOMEY EUFY
                  
                  {
                     module: "MMM-CommandToNotification",
                     disabled: false,
                     config: {
                      updateInterval: 300,
                      commands: [
                       
                  
                  
                  
                  {
                        	script: "/usr/bin/curl",
                        	args: "-s  http://192.168.100.244:3000/AUTBATTMEGANE",
                        	timeout: 1000,
                        	notifications: [
                         	"AUTBATTMEGANE",
                         	  ],
                       		},
                  
                       {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/BATTMEGANE",
                             timeout: 1000,
                             notifications: [
                              "BATTMEGANE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/PLUGMEGANE",
                             timeout: 1000,
                  			
                             notifications: [
                              "PLUGMEGANE",
                              ],
                            },
                  {
                             script: "/usr/bin/curl",
                             args: "-s  http://192.168.100.244:3000/CHARGEMEGANE",
                             timeout: 1000,
                  			
                             notifications: [
                              "CHARGEMEGANE",
                              ],
                            },
                  
                       ]
                     },
                    },
                  
                  
                  

                  But it doesn’t work, only the last element appears.

                  W 1 Reply Last reply Jan 24, 2023, 4:44 AM Reply Quote 0
                  • W Offline
                    wishmaster270 Module Developer @ELMAGO
                    last edited by Jan 24, 2023, 4:44 AM

                    @ELMAGO Hi,

                    thats right. The module does not support multi instance configurations.
                    You will need to copy the complete module folder and change some things to get it work.
                    But to me it looks like your server is stressed with the 16 calls straight after each other. So you do not need more parallelism but less.
                    So i will check if i can at a configurable delay after each command to stretch the time the calls get made to your server a little bit.

                    E S 2 Replies Last reply Jan 24, 2023, 8:19 AM Reply Quote 0
                    • E Offline
                      ELMAGO @wishmaster270
                      last edited by Jan 24, 2023, 8:19 AM

                      @wishmaster270

                      good morning

                      I don’t mind doing it by hand if you explain to me what I need to change

                      W 1 Reply Last reply Jan 24, 2023, 6:54 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 4 / 5
                      • 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