• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Timers and scripts

    Scripts
    script javascript valve
    3
    15
    7596
    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.
    • G
      gouds last edited by jkandasa

      Hi Guys. Liking this controller 🙂 I would like to know how to add in a timer that works like the following:
      I have a bunch of Valves (On/Off)
      Would like the rule to do the below:

      Master Valve - On
      Valve01 - On (Run for 10min); then
      Valve01 - Off; then
      Valve02 - On (Run for 10min); then
      Valve02 - Off; then
      Valve03 - On (Run for 10min); then
      Valve03 - Off; then
      Master Valve - Off

      Any pointers would be a great help.

      jkandasa 1 Reply Last reply Reply Quote 1
      • jkandasa
        jkandasa @gouds last edited by jkandasa

        @gouds We can do it in two ways. If you know programming, I recommend to use script to simplify this one. otherwise we can go with UI but it needs more entries.

        I will update soon. Thank you!

        jkandasa 1 Reply Last reply Reply Quote 0
        • jkandasa
          jkandasa @jkandasa last edited by jkandasa

          @gouds

          You can easily configure this sequence with script support. You have to do the followings,

          • Add uid tags for master-valve, valve01, valve02 and valve03. Using this uidtag we can easily access sensor variable from script.
          • Add an entry in Variable repository to check weather this script already running. If yes we can avoid duplicate running (which leads mall function on valve control), we have bug on this https://github.com/mycontroller-org/mycontroller/issues/269
          • Add script on Utilities >> Scripts
          • Create Execute script operation and point this script.
          • Configure a timer based on your requirement and point this operation.
          • Done! 🍰

          UID tags:

          0_1472665318409_upload-02aa3668-16fa-4c54-a6e3-aff922e3b9d0

          Variable repository entry:

          0_1472665375484_upload-dae2c4a2-0ec5-45d9-a566-61de7a9cb402

          Script (Javascript😞

          0_1472665433252_upload-3a28ceb1-283f-415f-8a05-749aa181f092

          Script source:
          var myImports = new JavaImporter(java.io, java.lang, java.util);
          
          with(myImports) {
            
            var valveStatus = mcApi.variable().get("valve-status");
          
            //Check already running?
            if(valveStatus.value !== 'running'){
              //Update as running
              valveStatus.value = "running";
              mcApi.variable().update(valveStatus);
              mcApi.logger().debug("valve-control script triggered...");
              
              var masterValve = mcApi.uidTag().getByUid("master-valve").getResource();
              var valve01 = mcApi.uidTag().getByUid("valve01").getResource();
              var valve02 = mcApi.uidTag().getByUid("valve02").getResource();
              var valve03 = mcApi.uidTag().getByUid("valve03").getResource();
                
              var delayTime = 1000 * 60 * 10; //10 minutes
            
              //Turn ON master valve and Valve01
              masterValve.value = "1"; //Update master valve ON state
              mcApi.sensor().sendPayload(masterValve); //sensd state
              valve01.value = "1"; //Update valve01 ON state
              mcApi.sensor().sendPayload(valve01); //sensd state
                
              //Update valve01 is running
              valveStatus.value2 = "value01";
              mcApi.variable().update(valveStatus);
            
            
              //Wait time
              Thread.sleep(delayTime);
            
              //Turn OFF valve01 and turn ON valve02
              valve01.value = "0"; //Update valve01 OFF state
              mcApi.sensor().sendPayload(valve01); //send state
              valve02.value = "1"; //Update valve02 ON state
              mcApi.sensor().sendPayload(valve02); //send state
              
              //Update valve02 is running
              valveStatus.value2 = "value02";
              mcApi.variable().update(valveStatus);
              
              //Wait time
              Thread.sleep(delayTime);
            
              //Turn OFF valve02 and turn ON valve03
              valve02.value = "0"; //Update valve02 OFF state
              mcApi.sensor().sendPayload(valve02); //send state
              valve03.value = "1"; //Update valve03 ON state
              mcApi.sensor().sendPayload(valve03); //send state
            
              //Update valve03 is running
              valveStatus.value2 = "value03";
              mcApi.variable().update(valveStatus);
            
              //Wait time
              Thread.sleep(delayTime);
            
              //Turn OFF valve03 and turn OFF master valve
              valve03.value = "0"; //Update valve03 OFF state
              mcApi.sensor().sendPayload(valve03); //send state
              masterValve.value = "0"; //Update master valve OFF state
              mcApi.sensor().sendPayload(masterValve); //send state
              
              //Update not running
              valveStatus.value = "stopped";
              valveStatus.value2 = "-";
              mcApi.variable().update(valveStatus);
              mcApi.logger().debug("valve-control script completted...");
            }else{
              mcApi.logger().warn("valve-control script is already running...");
            }
          }
          

          Create operation (Execute script😞

          0_1472665537182_upload-f02692b8-bdcf-4726-bf7f-c3d2f3621ca4

          Create timer:

          0_1472665730126_upload-f887b023-bf07-4cb5-95d7-5dd395e1baff

          IMPORTANT: There is bug in variable repository. I'm working on this. Until this issue resolved, updating current status of valve control will not work. You have to care do not run on multiple times. Once this fixed script will take care duplicates.
          Bug: https://github.com/mycontroller-org/mycontroller/issues/269

          1 Reply Last reply Reply Quote 0
          • G
            gouds last edited by

            Wow, thanks jkandasa. Was not expecting such a detailed reply. This is great. I went through and completed based on your instructions and i got the following when attempting to execute the script.

            {
            "errorMessage": "TypeError: org.mycontroller.standalone.api.SensorApi@11be5f8 has no such function "sendPayload" in <eval> at line number 23"
            }

            also found a small bug on the timer. (I will log this on the issues register)

            jkandasa 1 Reply Last reply Reply Quote 0
            • jkandasa
              jkandasa @gouds last edited by jkandasa

              @gouds Ah ok, I recently changed in 0.0.3.Final-SNAPSHOT as sendPayload but in old version it is sendpayload. Can you change on your script?

              sendPayload >> sendpayload.

              NOTE: When you upgrade to 0.0.3.Final, you have to change it back to sendPayload.

              Or from now you can download and use 0.0.3.Final-SNAPSHOT version from here.

              1 Reply Last reply Reply Quote 0
              • G
                gouds last edited by

                Grabed the new distro. Worked a treat. Thanks for your assistance.

                jkandasa 1 Reply Last reply Reply Quote 0
                • jkandasa
                  jkandasa @gouds last edited by

                  @gouds said:

                  also found a small bug on the timer. (I will log this on the issues register)

                  Timer issue has been fixed. you can take latest SNAPSHOT build.

                  https://github.com/mycontroller-org/mycontroller/issues/270

                  1 Reply Last reply Reply Quote 0
                  • G
                    gouds last edited by

                    Cheers. Ill give this a go.

                    1 Reply Last reply Reply Quote 0
                    • imedia
                      imedia last edited by

                      Hi, thanks for your post and example jkandasa,

                      I'm getting the following error:

                      "Cannot cast org.mycontroller.standalone.db.tables.SensorVariable to org.mycontroller.standalone.api.jaxrs.json.SensorVariableJson"

                      ideas?

                      1 Reply Last reply Reply Quote 0
                      • imedia
                        imedia last edited by

                        So I updated to 0.0.3.Final you posted. I stopped getting the error about the casting, but now none of my nodes register. Tried rebuilding from scratch re-adding the gateway and allowing it to auto discover. The gateway shows up and is responding but none of the sensor nodes register.

                        Tried rebooting the nodes, nothing

                        Tried re-flashing the firmware on the nodes, nothing.

                        When I go back to 0.0.3-Alpha2 the nodes register and all works but I'm then stuck again with the casting error.

                        ideas?

                        I feel like its a registration issue, like the nodes are expecting a certain version of controller, but if that's the case how do I resolve that?

                        Thanks again.

                        jkandasa 1 Reply Last reply Reply Quote 0
                        • jkandasa
                          jkandasa @imedia last edited by

                          @imedia There is no version control between MyController versions. Did you see any error logs on mycontroller/log/mycontroller.log? I have introduced register node option recently, just check Register nodes automatically is enabled on Settings >> System >> MyController >> Register nodes automatically.

                          1 Reply Last reply Reply Quote 0
                          • imedia
                            imedia last edited by jkandasa

                            OK,

                            In the logs on the FINAL version I seem to be getting this error repeatedly:

                            ERROR [pi4j-single-executor-0] [org.mycontroller.standalone.gateway.serialport.SerialDataListenerPi4j:79] Exception,

                            However, in Resources > Gateways the Gateway shows as connected, and in Resources > Nodes the gateway shows as seen a few seconds ago

                            So it looks like the gateway is talking... I also noticed this:

                            ERROR [Thread-5] [org.mycontroller.standalone.provider.mysensors.MySensorsProviderBridge:60] Unable to process this rawMessage:RawMessage(gatewayId=1, data==3,pt=0,l=0,sg=0:, subData=null, isTxMessage=false, networkType=MY_SENSORS, timestamp=1478210691023)
                            org.mycontroller.standalone.message.RawMessageException: Unknown message format:[=3,pt=0,l=0,sg=0:]
                            	at org.mycontroller.standalone.provider.mysensors.MySensorsRawMessage.updateSerialMessage(MySensorsRawMessage.java:139)
                            	at org.mycontroller.standalone.provider.mysensors.MySensorsRawMessage.<init>(MySensorsRawMessage.java:68)
                            	at org.mycontroller.standalone.provider.mysensors.MySensorsProviderBridge.executeRawMessage(MySensorsProviderBridge.java:58)
                            	at org.mycontroller.standalone.message.McMessageUtils.sendToProviderBridge(McMessageUtils.java:562)
                            	at org.mycontroller.standalone.message.MessageMonitorThread.processRawMessage(MessageMonitorThread.java:112)
                            	at org.mycontroller.standalone.message.MessageMonitorThread.run(MessageMonitorThread.java:191)
                            	at java.lang.Thread.run(Thread.java:745)
                            

                            If I change nothing and roll back to Alpha2 everything works fine.

                            jkandasa 1 Reply Last reply Reply Quote 0
                            • jkandasa
                              jkandasa @imedia last edited by

                              @imedia Looks like we have issue with pi4j serial driver. Can you please change your gateway driver from auto to JSerialComm and check?

                              1 Reply Last reply Reply Quote 0
                              • imedia
                                imedia last edited by

                                That seems to have done the trick thank you!

                                Do you think this is a bug or is it specific to my environment? Can I provide anything to you that will help with a resolution if it is a bug?

                                jkandasa 1 Reply Last reply Reply Quote 0
                                • jkandasa
                                  jkandasa @imedia last edited by

                                  @imedia I guess it should be a bug with recent pi4j driver. Let me setup serial gateway locally and narrow down the issue. Thank you so much for your support!

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

                                  0
                                  Online

                                  647
                                  Users

                                  506
                                  Topics

                                  3.3k
                                  Posts

                                  Copyright © 2015-2023 MyController.org | Contributors | Localization