Ankündigung

Einklappen
Keine Ankündigung bisher.

Why is my code not behaving like I was hoping

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Why is my code not behaving like I was hoping

    Why isn't this working? Between 23:00 and 5:45 the house should be in "night modus". When there is movement in the bathroom, the light should be switched on during this hours. Outside these hours, the light should not react to any movement.

    Is it because I had to define the variable "NACHTMODE = AUS"? I had to do so because otherwise eibpc wouldn't compile.

    Code:
    NACHTMODE = AUS
    if chtime(23,0,0) and !chtime(5,45,0) then {
      NACHTMODE = EIN
    } else {
      NACHTMODE = AUS
    } endif
     
    if (NACHTMODE==EIN) AND ("Melding_BadkamerBeweging-3/1/10"==EIN) then {
      write("Switch_Douche-0/2/11",EIN)
    } endif
    Second (basic and probably stupid) question. Is it correct that I have to write all my code in 1 user program? I cannot write a different user program to handle the web server and a different program to handle other logic. Is it correct that eibPC can only handle 1 user program?

    Tx for your support

    Ivan

    #2
    I think this is because at 23:00:00 the night mode is switched on for only one cycle. After this cycle the else-part is setting it to OFF.

    The code should be like this
    if htime(23,0,0) then NACHTMODE = EIN endif
    if htime(5,45,0) then NACHTMODE = AUS endif
    Gruß
    Volker

    Wer will schon Homematic?

    Kommentar


      #3
      Zitat von eulaersivan Beitrag anzeigen
      Second (basic and probably stupid) question. Is it correct that I have to write all my code in 1 user program? I cannot write a different user program to handle the web server and a different program to handle other logic. Is it correct that eibPC can only handle 1 user program?
      short answer: yes, everthing in one program
      ....und versuchen Sie nicht erst anhand der Farbe der Stichflamme zu erkennen, was Sie falsch gemacht haben!

      Kommentar


        #4
        Zitat von Uwe! Beitrag anzeigen
        short answer: yes, everthing in one program
        Hi

        Yes one program but you can use macros and write some yourself.
        Grüsse Bodo
        Fragen gehören ins Forum, und nicht in mein Postfach;
        EibPC-Fan; Wiregate-Fan; Timberwolf-Fan mit 30x 1-Wire Sensoren;

        Kommentar


          #5
          Zitat von eulaersivan Beitrag anzeigen
          Why isn't this working? Between 23:00 and 5:45 the house should be in "night modus". When there is movement in the bathroom, the light should be switched on during this hours. Outside these hours, the light should not react to any movement.

          Is it because I had to define the variable "NACHTMODE = AUS"? I had to do so because otherwise eibpc wouldn't compile.

          Code:
          NACHTMODE = AUS
          if chtime(23,0,0) and !chtime(5,45,0) then {
            NACHTMODE = EIN
          } else {
            NACHTMODE = AUS
          } endif
           
          if (NACHTMODE==EIN) AND ("Melding_BadkamerBeweging-3/1/10"==EIN) then {
            write("Switch_Douche-0/2/11",EIN)
          } endif
          chtime(5,45,0) will be on after that time for the rest of the day. That means !chtime(5,45,0) should be false for the rest of the day.

          I have no EibPC here at hands but the following should do the job:

          Code:
          NACHTMODE = EIN
          if chtime(5,45,0) and !chtime(23,0,0) then {
            NACHTMODE = AUS
          } else {
            NACHTMODE = EIN
          } endif
          Regards,
          Bernd

          Kommentar


            #6
            I think your prpblem is, you should also add an event.
            Otherwise the System would act only once a night...

            if (NACHTMODE==EIN) AND ("Melding_BadkamerBeweging-3/1/10") and event("Melding_BadkamerBeweging-3/1/10") then {
            write("Switch_Douche-0/2/11",EIN)
            } endif



            Second (basic and probably stupid) question. Is it correct that I have to write all my code in 1 user program? I cannot write a different user program to handle the web server and a different program to handle other logic. Is it correct that eibPC can only handle 1 user program?
            All code is executed in parallel each process cycle. There is no need for different user "tasks". Our what is your intention?
            offizielles Supportforum für den Enertex® EibPC: https://knx-user-forum.de/eibpc/
            Enertex Produkte kaufen

            Kommentar


              #7
              Code:
              if chtime(23,0,0) and !chtime(5,45,0) then
              Let us see what will happen:

              'chtime(23,0,0)' will be 0 from 00:00 till 23:00 and 1 from 23:00 till 00:00
              '!chtime(5,45,0)' will be 1 from 00:00 till 05:45 and 0 from 05:45 till 00:00

              What happens at 23:00? 'chtime(23,0,0)' changes to 1 while '!chtime(5,45,0)' remains 0. 1 and 0 is still 0 -> else...
              What happens at 00:00? 'chtime(23,0,0)' changes to 0 and '!chtime(5,45,0)' changes to 1. 0 and 1 is still 0 -> else...
              What happens at 05:45? 'chtime(23,0,0)' remains 0 while '!chtime(5,45,0)' changes to 0. 0 and 0 is still 0 -> else...
              What happens at other times? As long as no signal changes the expression is not evaluated! -> nothing happens and 'NACHTMODE' remains 'AUS'

              'NACHTMODE' remains 'AUS' all the time, I think that is not what you like to have.

              Perhaps it will works if you use 'or' instead of 'and':

              What happens at 23:00? 'chtime(23,0,0)' changes to 1 while '!chtime(5,45,0)' remains 0. 1 or 0 is 1 -> then...
              What happens at 00:00? 'chtime(23,0,0)' changes to 0 and '!chtime(5,45,0)' changes to 1. 0 or 1 is 1 -> then...
              What happens at 05:45? 'chtime(23,0,0)' remains 0 while '!chtime(5,45,0)' changes to 0. 0 or 0 is 0 -> else...

              I think that is what you like to have.


              But I think the code is more readable and easier to understand if it is written like this:
              Code:
              NACHTMODE = AUS
              if chtime(23,0,0)  then {
                NACHTMODE = EIN
              } endif
              if chtime(5,45,0) then {
                NACHTMODE = AUS
              } endif
               
              if (NACHTMODE==EIN) AND ("Melding_BadkamerBeweging-3/1/10"==EIN) then {
                write("Switch_Douche-0/2/11",EIN)
              } endif
              OK, the code does not work correct when restarted between 00:00 and 05:45. But I'm not sure if the other code does.
              I do not know, if this code is evaluated when the EibPC is restarted
              Code:
              if chtime(23,0,0) and !chtime(5,45,0) then
              is evaluated when the EibPC is restarted between 00:00 and 05:45.
              'chtime(5,45,0)' is and remains 0 so there is no change at all. Im affraid in both versions you do not get what you want if you restart the programm between 00:00 and 05:45. That's the disadvantage of the event driven evaluation...

              So finally we have to put all conditions in one expression:

              Code:
              if (chtime(23,0,0) OR !chtime(5,45,0)) AND ("Melding_BadkamerBeweging-3/1/10"==EIN) then {
                write("Switch_Douche-0/2/11",EIN)
              } endif
              Here we use '"Melding_BadkamerBeweging-3/1/10"==EIN' as trigger to force an evaluation also between 00:00 and 05:45.
              This expression should set '"Switch_Douche-0/2/11",EIN' whenever '"Melding_BadkamerBeweging-3/1/10"' changes to 'EIN' inbetween 23:00 and 05:45. And it will set '"Switch_Douche-0/2/11",EIN' if '"Melding_BadkamerBeweging-3/1/10"' is already 'EIN' while time is changing from before 23:00 to 23:00.
              But I don't know when '"Switch_Douche-0/2/11"' is set to 'AUS'. Your original code doesn't do that at any time...
              Tessi

              Kommentar


                #8
                Thanks a lot for all your replies. I'll try Tessi's solution.

                In ETS it is defined that the movement detector will send an AUS telegram "By Ablauf Bewegungszeit". Based on this, I didn't bother defining an AUS telegram in eibPC. Or will this be wrong?

                Tx - Ivan

                Kommentar


                  #9
                  That depends on the configuration of the detector and/or the actuator...
                  Your code implies that the movement detector sends 'EIN' to 3/1/10 and that the EibPC than shall send 'EIN' to 0/2/11 if time is beetween 23:00 and 05:45, otherwise the EibPC shall do nothing.
                  Usually, a movement detector sends 'EIN' and 'AUS' to the same adress, and usually if an actuator reacts on an adress than for all values.
                  If you use 3/1/10 for the detector and 0/2/11 for the actuator, than the 'AUS' from the detector never reaches the actuator. If you use both adresses for the actuator, than he always will react on the detector.
                  Only if you either can configurate the detector to send 'EIN' to 3/1/10 (only) and 'AUS' to 0/2/11 (too) or you can configurate the actuator to react on 3/1/10 only to 'AUS' while reacting for 0/2/11 to 'EIN' (and may be 'AUS', too, that is not sended by the EibPC).
                  But in the first case you will can get a problem with the trigger condition '("Melding_BadkamerBeweging-3/1/10"==EIN' if the detector will only send 'EIN' but no 'AUS' to 3/1/10. Than the expression is evaluated only once after a restart of the EibPC (since at start the value for the EibPC is set to 'AUS' ) when the 'EIN' is received for the first time, than never again since there will be no more change. But you could avoid that by checking for an update of the value, too (like in the posting of enertegus), instead of only checking for a change of the value. BUT:
                  Expecting that you can use only one adress for sending and the actuator will treat several adresses equal for all values, the savest way will be to pass the command through the EibPC (by adding following statement):
                  Code:
                  if ("Melding_BadkamerBeweging-3/1/10"==AUS) then {
                    write("Switch_Douche-0/2/11",AUS)
                  } endif
                  Than the EibPC is always gating 3/1/10 to 0/2/11 independent of the value.
                  Tessi

                  Kommentar


                    #10
                    Hallo,
                    you make your life much easier, when you work it the other way round:
                    If you define "day-modus" between 8°° and 23°°h you stay within the same day and is just one definition
                    if chtime (8,0,0) and !chtime (23,00,00) then day=1bo1 else day=0b01 endif

                    In the further program you either use !day or you create a variable
                    like:
                    if !day then night=1b01 else night=0b01 endif
                    Der schöne Niederrhein läßt Grüssen

                    Andreas


                    Alter Hof mit neuer Technik

                    Kommentar


                      #11
                      That means:
                      Code:
                      if chtime(5,45,0) and !chtime(23,0,0) then {
                        DAYMODE = EIN
                      } else {
                        DAYMODE = AUS
                      } endif
                       
                      if (DAYMODE==AUS) AND ("Melding_BadkamerBeweging-3/1/10"==EIN) then {
                        write("Switch_Douche-0/2/11",EIN)
                      } endif
                       
                      if ("Melding_BadkamerBeweging-3/1/10"==AUS) then {
                        write("Switch_Douche-0/2/11",AUS)
                      } endif
                      If the movement detector sends 'EIN' and 'AUS' to 3/1/10 and the actuator is listening to 0/2/11 this should work...
                      Tessi

                      Kommentar


                        #12
                        Beware of the validation scheme, better add an event handler as enertegus wrote before...

                        Code:
                        if chtime(5,45,0) and !chtime(23,0,0) then {
                          DAYMODE = EIN
                        } else {
                          DAYMODE = AUS
                        } endif
                         
                        if (DAYMODE==AUS) AND ("Melding_BadkamerBeweging-3/1/10"==EIN) [I][COLOR=Red]and event("Melding_BadkamerBeweging-3/1/10") [/COLOR][/I]then {
                          write("Switch_Douche-0/2/11",EIN)
                        } endif
                         
                        if ("Melding_BadkamerBeweging-3/1/10"==AUS) [I][COLOR=Red]and event("Melding_BadkamerBeweging-3/1/10") [/COLOR][/I]then {
                          write("Switch_Douche-0/2/11",AUS)
                        } endif
                        Regards,
                        Bernd

                        Kommentar

                        Lädt...
                        X