HTTP Get request with header authentication

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • Pilaarbijter
    Smart Home'r
    • 21.11.2020
    • 39

    #1

    HTTP Get request with header authentication

    Hello everyone,

    In short I have this WIFI-heater from Adax that I would like to command to change the temperature via theLocal API
    (link)

    Snippet of most important information on the above mentioned site:

    Klicke auf die Grafik für eine vergrößerte Ansicht  Name: snippet.jpg Ansichten: 0 Größe: 66,5 KB ID: 428049

    I am trying to get a HTTP get request done via Loxone but I don't seem to get it working. I added printscreens of what I have in Loxone thus far. I probably need the Unix time
    from Loxone but I can't wrap my head around how to import it into my request.


    Klicke auf die Grafik für eine vergrößerte Ansicht  Name: hoofd.jpg Ansichten: 0 Größe: 69,6 KB ID: 428050




    Klicke auf die Grafik für eine vergrößerte Ansicht  Name: input.jpg Ansichten: 0 Größe: 129,5 KB ID: 428051










    I programmed the same request in a Python script and everything is going flawlessly. (code below)

    This leads me to believe that there probably is a problem with the concept unix time that is required to run the command.

    I'm planning on making a full HowTo about this adventure, so any help here would be great for the community aswel


    Working Python-code
    -------------------------

    Code:
    #! /usr/bin/bash python3
    
    # controls heater
    
    # install dependencies with: pip install bleak requests
    
    import http.client
    
    import urllib
    
    import time
    
    import requests
    
    import urllib3
    
    
    HEATER_IP = '192.xxxxxxx # replace with your heater IP from the prepare_demo
    
    HEATER_TOKEN = 'xxxxxxx' # replace with your secure password from the prepare_demo
    
    def get_status():
    
    url = 'https://' + HEATER_IP + '/api'
    
    payload = { 'command': 'stat', 'time': int(time.time()) }
    
    headers = { 'Authorization': 'Basic ' + HEATER_TOKEN }
    
    response = requests.get(url, params = payload, headers = headers, timeout = 15, verify = False)
    
    response_json = response.json()
    
    target_temperature = response_json["targTemp"]
    
    current_temperature = response_json["currTemp"]
    
    print('Current temperature %d, target temperature: %d \n' % (current_temperature, target_temperature))
    
    urllib3.disable_warnings() # heater uses self signed certificate
    
    get_status()
    
    
    exec(open('PushoverDown.py').read())
  • Tico
    Lox Guru
    • 31.08.2016
    • 1035

    #2
    Replace <v1> with <v>. Only <v> is accepted in a Virtual Output.

    If <v> is used, the expectation is that the Unix Timestamp would be at the entry to the Virtual Output. Use as Digital Output should be unchecked. The Unix Timestamp is available in the Time functions -

    Klicke auf die Grafik für eine vergrößerte Ansicht  Name: Unix Timestamp.png Ansichten: 0 Größe: 7,7 KB ID: 428057

    But this would also mean a command is sent on every change (every second).

    You really need a Status Block with a trigger to allow the Timestamp through only when desired. This also sends a 0 on Off. This may be an issue without testing.

    Klicke auf die Grafik für eine vergrößerte Ansicht  Name: Trigger.png Ansichten: 0 Größe: 16,4 KB ID: 428058
    Zuletzt geändert von Tico; 30.03.2024, 03:11.
    Ich spreche kein Deutsch. Gib Google Translate die Schuld, wenn ich unverständlich bin.

    Kommentar

    • Pilaarbijter
      Smart Home'r
      • 21.11.2020
      • 39

      #3
      Thanks for the reply!


      Sadly the adaptations to this set-up don't seem to work.


      Klicke auf die Grafik für eine vergrößerte Ansicht  Name: config.jpg Ansichten: 0 Größe: 16,3 KB ID: 428137

      Klicke auf die Grafik für eine vergrößerte Ansicht  Name: config2.jpg Ansichten: 0 Größe: 8,4 KB ID: 428138


      I was able to verify the following command via Postman without any issues (it increase the desired temperature to 14 degrees celcius):


      https://192.xxx.x.xxx/api?command=set_target&value=1400&time={{$timestam p}}


      This leads me to believe that there is a problem in Loxone with the Unix Timestamp not being transported into the URL properly.

      EDIT:

      I also considered your remark regarding the zero/off value being a potential problem. Although it might be responsible for an overload of commands towards the heater, it does not explain the problem of the temperature not changing (since a request sent is a request sent (I think).

      Zuletzt geändert von Pilaarbijter; 30.03.2024, 23:53.

      Kommentar

      • Tico
        Lox Guru
        • 31.08.2016
        • 1035

        #4
        I'm more inclined to think it may be a problem with the 'HTTP header for On'. Just change your token to something false and send a screenshot of exactly how the line looks.

        edit:
        And what does the Postman header look like?

        The other issue may be the 'https'. Are you on a Miniserver Gen1 or Gen2?
        Zuletzt geändert von Tico; 31.03.2024, 00:01.
        Ich spreche kein Deutsch. Gib Google Translate die Schuld, wenn ich unverständlich bin.

        Kommentar

        • Pilaarbijter
          Smart Home'r
          • 21.11.2020
          • 39

          #5
          Could you specify on 'how the line looks' that you would like to see? I'm not really sure what you mean by that. A diagnostic report of sorts?

          Set-up in Postman:


          Klicke auf die Grafik für eine vergrößerte Ansicht

Name: postman.jpg
Ansichten: 436
Größe: 37,4 KB
ID: 428142

          Token is set up: Basic xxxTOKENxxxx

          I reckon my server is Gen 2. It was installed in 2019 and is limegreen.

          Kommentar

          • Pilaarbijter
            Smart Home'r
            • 21.11.2020
            • 39

            #6
            Nevermind, I'm such an idiot. I forgot to add the "Authorization:" to my header for on in Loxone. Unbelievable.

            Thanks for the help though, it's much appreciated

            Kommentar

            • Tico
              Lox Guru
              • 31.08.2016
              • 1035

              #7
              I thought this looked a bit short....


              Klicke auf die Grafik für eine vergrößerte Ansicht

Name: HTTP Header.png
Ansichten: 431
Größe: 41,7 KB
ID: 428150
              Ich spreche kein Deutsch. Gib Google Translate die Schuld, wenn ich unverständlich bin.

              Kommentar

              • eIRIk
                Dumb Home'r
                • 27.03.2018
                • 10

                #8
                Did you get adax to work? If yes. How did you request the token? Did you use the program block?
                Miniserves v1 & v2 v14.7.3.6, Test Miniserver v1, Relay Ext., 7xDimmer Ext., 1-Wire Ext. Modbus ext., Air Ext, RS485 Ext. 8xRGBW Dimmer Ext, Tree Ext., 2xtree to air, Wether station, KebaContact P20, Intercom +++ Loxberry: MiRobot2Lox, TinyTuya Ventilation: System Air via Modbus RTU AMS: PowU, HomeConnect, PowerWiew Shading, Husqvarna Automover

                Kommentar

                Lädt...