Announcement

Collapse
No announcement yet.

A little help with programming device strings

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

    A little help with programming device strings

    I am working on my hs website, and I am trying to color code my alarm status to red and green depending on armed or disarmed. I receive an email from my monitoring company that either says "authorized arm by (whoever arms, ie beach)" or "authorized disarm by (whoever disarms)" I would like to parse the phrases so that all the script sees is "authorized arm". If it sees this, the color is red. If not, it is green. Here is what I have so far. \

    if body="Authorized Arm by Beach" then
    hs.setDeviceString "E1","<font color='green'>body</font>"
    else hs.setDeviceString "E1",body
    end if
    hs.setdeviceString "E2",date

    It only puts in the word "body" instead of the value of body, which would be either arm or disarm.

    #2
    The second line, the body is inside the "" it should be like this
    hs.setDeviceString "E1","<font color='green'>" & body & "</font>"

    Comment


      #3
      I'll give that a try. I got it to work like this:

      greenbody=body
      if body="Authorized Arm by Beach" then
      body="<font color='green'>" & body & "</font>"
      end if
      hs.setDeviceString "E1",body
      hs.setdeviceString "E2",date

      Does anyone know how to parse so that it only sees "authorized arm"?

      Comment


        #4
        <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by Beach:
        I'll give that a try. I got it to work like this:

        greenbody=body
        if body="Authorized Arm by Beach" then
        body="&lt;font color='green'&gt;" & body & "&lt;/font&gt;"
        end if
        hs.setDeviceString "E1",body
        hs.setdeviceString "E2",date

        Does anyone know how to parse so that it only sees "authorized arm"? <HR></BLOCKQUOTE>

        if instr(lcase(body),"authorized arm") &gt; 0 then


        ~Bill

        Comment


          #5
          I think I posed the wrong question. I would like the script to see what is contained in the variable body. If body = "Authorized Arm by Bob" (or any name that might arm the alarm), I would like the script to only recognize the words "Authorized Arm", and then if so, color the variable body's string red, otherwise color the variable body's string green.

          Comment


            #6
            Is this what you want?


            if instr(lcase(body),"authorized arm") &gt; 0 then 'Looks to see if authorized arm is in the string 'body'

            'The following is for 'authorized arm' being found in the
            'variable body and the font will be RED
            body = "&lt;tr&gt;&lt;td width=25% &lt;font color='#00CC00'&gt;&lt;p&gt;&lt;style='word-spacing: 0; margin: 0'&gt; " & body & "&lt;/p&gt;&lt;/td&gt;"

            else

            'The following is for a string that doesn't
            'contain 'authorized arm' and it will be RED
            body = "&lt;tr&gt;&lt;td width=25% &lt;font color='#FF0000'&gt;&lt;p&gt;&lt;style='word-spacing: 0; margin: 0'&gt; " & body & "&lt;/p&gt;&lt;/td&gt;"


            end if

            hs.setDeviceString "E1",body
            hs.setdeviceString "E2",date '&lt;-- If this doesn't work, try Date() instead



            ~Bill
            <BLOCKQUOTE class="ip-ubbcode-quote"><font size="-1">quote:</font><HR>Originally posted by Beach:
            I think I posed the wrong question. I would like the script to see what is contained in the variable body. If body = "Authorized Arm by Bob" (or any name that might arm the alarm), I would like the script to only recognize the words "Authorized Arm", and then if so, color the variable body's string red, otherwise color the variable body's string green. <HR></BLOCKQUOTE>


            ~Bill

            Comment


              #7
              Bill,

              For some reason, it doesn't work. It's always red.

              Comment


                #8
                Tell me what your log says:

                hs.writelog "DEBUG" , lcase(body)
                hs.writelog "DEBUG" , instr(lcase(body),"authorized arm")

                if instr(lcase(body),"authorized arm") &gt; 0 then 'Looks to see if authorized arm is in the string 'body'

                'The following is for 'authorized arm' being found in the
                'variable body and the font will be GREEN
                hs.writelog "DEBUG" , "GREEN"
                body = "&lt;tr&gt;&lt;td width=25% &lt;font color='#00CC00'&gt;&lt;p&gt;&lt;style='word-spacing: 0; margin: 0'&gt; " & body & "&lt;/p&gt;&lt;/td&gt;"

                else

                'The following is for a string that doesn't
                'contain 'authorized arm' and it will be RED
                hs.writelog "DEBUG" , "RED"
                body = "&lt;tr&gt;&lt;td width=25% &lt;font color='#FF0000'&gt;&lt;p&gt;&lt;style='word-spacing: 0; margin: 0'&gt; " & body & "&lt;/p&gt;&lt;/td&gt;"


                end if

                hs.setDeviceString "E1",body
                hs.setdeviceString "E2",date '&lt;-- If this doesn't work, try Date() instead


                ~Bill

                Comment


                  #9
                  Bill. Thank you. It works. I had some capital letters where they should have been lowercase.

                  Comment


                    #10
                    Ya, if I am working on a big, new script, I scatter those debugs everywhere.

                    Usually though, I will add if/then statements before all the DEBUG writelogs so I can turn on and off all the debugging easily.

                    debug = 1
                    ...
                    if debug = 1 then hs.writelog "DEBUG" , "GREEN"
                    ...
                    if debug = 1 then hs.writelog "DEBUG" , "RED"
                    ...

                    and so on. Good luck!


                    ~Bill

                    Comment

                    Working...
                    X