Announcement

Collapse
No announcement yet.

Irrigation control with mcsTasmota

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Irrigation control with mcsTasmota

    http://mcsSprinklers.com/mcsTasmota.zip and http://mcsSprinklers.com/mcsTasmota6.zip contains binary images of Tasmota firmware used in Sonoff and similar ESP micro-controllers that has been augmented for irrigation control.

    These images will control irrigation on an interval where the user specifies the interval, ON duration, and optionally hour of day to start. They will also accept scheduling commands and direct ON/OFF control commands to control each relay of the unit. This is normally done via MQTT protocol.

    This discussion will consider only the MQTT route and HomeSeer. For MQTT interface either mcsMQTT or mcsSprinklers plugins will be discussed. The easiest setup for irrigation is with mcsSprinklers as this plugin is designed explicitly for irrigation, but it has capabilities that go well beyond the minimum required to use mcsTasmota. mcsMQTT is more generic and does not have an irrigation context, but basic control can be done using it and HomeSeer.

    The assumption for this discussion is that a Sonoff 4CH Pro (or Sonoff 4CH Pro R2) has been flashed with mcsTasmota, Mosquitto or other MQTT broker is running on the user network and either mcsMQTT or mcsSprinklers has been enabled under HS3. Each will be a separate use case.

    The next step is to tell mcsTasmota what the backup/failover irrigation schedule will be. This needs to be done only one time, but can be changed as the irrigation needs change. The easiest way to do this is with Publist using mcsMQTT. For this example the following assumptions are made:
    1. Sonoff 4CH has been setup with GPIO2 used for enable/disable (first figure)
    2. Sonoff 4CH has been setup with Topic 'IrrigationValve' (second figure)

    The 4CH will report status using the IrrigationValve/STATE topic every 5 minutes. An example is below that shows all 4 relays (POWER) are OFF as well as information about Wifi and Uptime.

    Code:
    IrrigationValve/STATE={"Time":"2018-06-16T18:57:22","Uptime":"0T06:53:51","Vcc":3.190,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF",  ,"Wifi":{"AP":1,"SSId":"U","RSSI":64,"APMac":"78:8A:20:84:48:1D"}}
    After the irrigation has been enabled then the payload of the topic will include an irrigation section such as below. Enabling irrigation will be discussed later. In this case it is reporting that irrigation is in AUTO mode which means it will monitor HS for relay control and if HS has not turn on the first relay within then next 259 minutes then mcsTasmota will turn it ON. Similar for relays 2,3, and 4 with different times. Setting these times will be discussed later.
    Code:
    IrrigationValve/STATE={"Time":"2018-06-16T18:57:22","Uptime":"0T06:53:51","Vcc":3.190,"POWER1":"OFF","POWER2":"OFF","POWER3":"OFF","POWER4":"OFF", "Irrigation":{ "IrrigationMode":"AUTO", "Time1":"259", "Time2":"258", "Time3":"257", "Time4":"258"} ,"Wifi":{"AP":1,"SSId":"U","RSSI":64,"APMac":"78:8A:20:84:48:1D"}}
    When mcsTasmota turns a relay ON of OFF it will report the event using a topic similiar to below where in this case it is relay 4 being turn ON.
    Code:
    IrrigationValve/POWER4=ON
    HS can command the relay to be turned ON using the same topic with /cmnd inserted. This is shown below:

    Code:
    IrrigationValve/cmnd/POWER4=ON
    HS can provide this command via mcsMQTT in various ways which include changing a HS device to ON or triggering an event that sends this message. This command is provide automatically by mcsSprinklers when it determines it is time to control the relay.
    Attached Files

    #2
    Irrigation Control via only mcsTasmota

    When mcsTasmota does not receive any ON or OFF commands for the specified period of time it will enter was is called the fallback scheduling to assure that irrigation continues even though some master HA system has failed in providing the expected control.

    For this example the fallback program is to run each relay, except relay 3, for 30 minutes every 4320 minutes (3 days). Relay 3 will be 60 minutes every 2 days (2880 minutes). mcsMQTT is setup with a Publist as shown in attachment that specifies this program. $$ variables are substitution variables use that can be used with mcsMQTT with the top part showing the definition and the lower part the template where the substitution is applied. For example $$1: is replaced by 'IrrigationValve'. This allow the module/topic (IrrigationValve) to change and the template remains intact without editing. The Publist is sent to mcsTasmota with the Execute Publication List button.

    MQTT commands such as 'IrrigationValve/cmnd/IrrigationOnMinutes' with payload of 30 can also be sent with other mechanisms such as a Mosquitto client.

    In this use case it is assumed that no further use of mcsMQTT or mcsSprinklers is done for irrigation. mcsTasmota will irrigate on a schedule of 30 minutes ON every 3 days for relay 1,2, and 4 and 60 minutes ON every two days for relay 3.

    Note: The use of IrrigationOnMinutes and IrrigationOffMinutes without a specific relay suffix is only supported with mcsTasmota 5.9.13 and 6.0.0.1. Earlier versions require explicit relay identification such as was done for relay 3 in this example.
    Attached Files
    Last edited by Michael McSharry; June 16, 2018, 11:22 PM.

    Comment


      #3
      Irrigation Control via HS and mcsMQTT

      Irrigation control with mcsTasmota can be done with or without a fallback program set in mcsTasmota. It is recommended that a fallback is setup to guard against failure modes associated with HS. The fallback scheduling is shown in the prior post.

      This example will use the case of the four relays are mapped into four HS devices. When the HS device is turn ON then the relay will turn ON and the same for the OFF case. mcsMQTT will perform the association. This can be done manually, but the easiest way is to have mcsTasmota disclose the relay status so that mcsMQTT will see it and then the use can Accept it as a HS device. The 4Ch has a button to turn ON/OFF each relay. If these buttons are toggled then the MQTT messages will be published and mcsMQTT will see them. The Association tab of mcsMQTT can then be viewed as shown in the attachment.

      Initially the topic will be shown such as in rows 200 through 210 in the attachment. The "A" column checkbox is then selected to map the topic into HS device. After that the Pub topic is specified which will be the same as the status topic that is being viewed, but /cmnd is inserted.

      In this case HS devices 258 through 261 have been associated with the four 4CH relays. These devices can be manually controlled from Device Management page for checkout. After proven then events can be setup as to when the relay should be turn ON and OFF.

      If the fallback schedule has been programmed into mcsTasmota then the events should be setup so the ON is more frequent than the fallback otherwise the fallback will become active and undesired ON control will occur. Even if a fallback schedule has been setup, an additional message can be sent to set IrrigationMode to OFF if this monitoring is not desired.
      Attached Files

      Comment


        #4
        Irrigation Control via mcsSprinklers

        mcsSprinklers supports many types of irrigation valve controllers including those that are addressed by MQTT. Just as with HS/mcsMQTT control it is desirable to have a fallback schedule programmed in mcsTasmota, but again also not required.

        mcsSprinklers also provides a prediction as to when the next irrigation cycle for each zone/valve/relay will occur. mcsTasmota will accept this predicted time and not go into fallback irrigation mode until after this time as well as the programmed fallback interval has expired. This allow the dynamic scheduling based upon weather to be implemented with mcsTasmota.

        mcsSprinklers is setup just as with any other valve controller with moisture consideration, water use considerations, city restrictions, optimal moisture-based scheduling etc. For the valve the setup will be via MQTT as shown in attachment. Note that the setup has a subscribe status with two entries. The first is the topic returned to acknowledge the relay has changed as commanded. The second is the periodic status showing the relay state. mcsSprinklers uses both to assure integrity of the irrigation system.
        Attached Files

        Comment


          #5
          Many thanks.
          Don

          Comment


            #6
            Thanks to Pete and Michael, I'm close to be up and running. Appreciate the help, guys.
            Don

            Comment


              #7
              Don, you had problems initially with Wifi connection to Sonoff. Can you summarize your difficulty and what you had to do to get things working? What version of mcsTasmota did you end up using? Are you implementing the local override by installilng switch on Sonoff? What is your approach/strategy for irrigation control? What can I do to make it easier for the next person?

              Comment


                #8
                Michael;

                Your first few posts answered most of the questions I had. Originally Pete helped me with the OTA firmware upgrade. When I looked for the Sonoffs, I wasn't looking at my router but using fing on my phone. Once I found them, looking through the router, I could connect but the command language threw me off. After looking at your examples I got it.

                I hope that answers your question. And thanks again.
                Don

                Comment


                  #9
                  After having this up and running for a couple of days, I am really happy with the two Sonoffs.
                  Don

                  Comment


                    #10
                    Thanks Don. I like the units as well.

                    Comment


                      #11
                      Well, the honeymoon is over. One of the Sonoff's went off line, and I can't get it to come back. Tried a reset but the blue light is blinking. I'm going to leave if off for a while and hope it comes back to life.

                      Bummer.
                      Don

                      Comment


                        #12
                        Had you been looking at RSSI previously to understand the signal strength at the location it was installed?

                        What version of firmware do you have installed?

                        How much Wifi do you have that is competing for time to access the AP? One approach is to setup a AP for these units that uses a channel that does not overlap with your main AP. From memory these are 1, 6 and 13.

                        I just took a look at all of my device RSSI (mcsMQTT, Association Page, Filter J2 for RSSI) and have range of 66 to 98

                        I just setup to collect the LWT (Last Will and Testimate) topic (Association Page T2 filter) and checked all the H checkboxes so data will be collected and I can see the history if any of my devices are going offline at times. I have several test devices that are now unplugged. This setup is shown in attachment. After data is collected then chart tab can be used to view it. The general tab needs to be setup to allow data collection for a specified period of time with at least the H checkbox selection enabled.

                        When Tasmota goes offline it cycles with WiFi CFG, AP at 192.1658.4.1, connect to either of two defined APs. This means that if they do go offline they will get back online with the AP when the conditions allow it.
                        Attached Files

                        Comment


                          #13
                          I had been collecting history for everything so already had the LWT. All my devices had just one dropout and at the same time so likely something external to them. The other is the garage door which has a poorer RSSI. It dropped out and came back multiple times. Notice that my RSSI has been trending better over the past few weeks with a low period in the middle.
                          Attached Files

                          Comment


                            #14
                            Hi Michael;

                            Not blowing you off, but I've had my hands full with things at home. I'll reread your notes (thanks for them) and will get back to you soon.
                            Don

                            Comment


                              #15
                              I have some time to deal with this, so I will try to reply to Michael's questions.

                              The one Sonoff that went offline is now back but I can not contact the web page. I can still control the relays. Strange.

                              Filtering for RSSI I can see one Sonoff with a payload of 68 and the problem Sonoff of 58. I can't access the webpage for the other values you were curious about.

                              I just enabled the history function for LWT and will report back when I have something to show.

                              Is there some way to program the modules to turn off if contact is lost? I was looking at your image of publishing but wasn't clear if I could just have the relays default to open.

                              I'm sorry that I'm a pain in the #*** with this stuff, but I am really struggling to understand it. Not your fault, I'm just dense.
                              Don

                              Comment

                              Working...
                              X