metbosch / homebridge-http-temperature

HomeBridge HomeKit Plugin for HTTP temperature endpoints
https://www.npmjs.com/package/homebridge-http-temperature
Apache License 2.0
33 stars 18 forks source link

Question: Header #30

Closed mbierman closed 2 years ago

mbierman commented 2 years ago

To connect to my device, I need to send a header for auth. Is that supported?

metbosch commented 2 years ago

Currently there is only support for basic http auth (see auth option in README).

Adding support for custom headers should not be a hard work. However, I cannot promise any deadline, but pull requests are welcome ;) Anyway, would you be able to test an experimental module version if I find the time to develop the changes?

mbierman commented 2 years ago

Thanks. I think that would be a great improvement! Yes, I would be happy to help with testing.

I was actually trying to use this to replace another plugin which seems to be deprecated. My thought was to show voltage rather than temperature. I started to hack around and it sort of worked, but I ran into some issues and haven't had enough time to work through them. Ideally, I could use the API to fetch the current Watt consumption and display it. I don't know if this would be better as a fork of your plugin or if you would consider broadening the purpose of yours to support Watts in addition to temperature perhaps with a few flags (max wattage, min wattage, units, etc.)

metbosch commented 2 years ago

Let's go step by step.

First, can you try latest changes in master branch? Version 0.9.0 It is not published in npm yet, I will wait until your feedback. The changes remove the deprecated request dependency and add support for custom headers.

Regarding, the power accessory. If you provide the link to the homebridge documentation, we can take a look. The official page is: https://developers.homebridge.io/#/

mbierman commented 2 years ago

@metbosch sure will do.

Also am I doing this wrong? Do I need to manually pull down the files? image

mbierman commented 2 years ago

O.K. so I manually updated the install. Here is what I have

       {
            "accessory": "HttpTemperature",
            "name": "Neurio",
            "manufacturer": "Neurio",
            "serial": "300",
            "url": "http://neurio.lan/current-sample",
            "http_method": "GET",
            "field_name": ".channels[1].p_W",
            "units": "F",
            "update_interval": 10000,
            "min_temp": 10,
            "max_temp": 10000,
            "debug": true,
            "auth": {
                "user": "X",
                "pass": "XXXX"
            }
        }
    ],

Questions should these values be quoted?

"min_temp": 10,
"max_temp": 10000,
"update_interval": 10000,

The overall response from my URL looks like

{
    "sensorId": "0x0000C47F51019A27",
    "timestamp": "2022-03-18T18:25:38Z",
    "channels": [
        {
            "type": "PHASE_A_CONSUMPTION",
            "ch": 1,
            "eImp_Ws": 74225753311,
            "eExp_Ws": 639931,
            "p_W": 399,
            "q_VAR": 28,
            "v_V": 121.144
        },
        {
            "type": "CONSUMPTION",
            "ch": 2,
            "eImp_Ws": 89193271933,
            "eExp_Ws": 96708,
            "p_W": 399,
            "q_VAR": 28,
            "v_V": 121.144
        }
    ],
    "cts": [
        {
            "ct": 1,
            "p_W": 399,
            "q_VAR": 28,
            "v_V": 121.144,
            "i_A": 3.704
        },
        {
            "ct": 2,
            "p_W": 242,
            "q_VAR": 2,
            "v_V": 121.106,
            "i_A": 2.130
        },
        {
            "ct": 3,
            "p_W": 0,
            "q_VAR": 0,
            "v_V": 0.258,
            "i_A": 0.000
        },
        {
            "ct": 4,
            "p_W": 0,
            "q_VAR": 0,
            "v_V": 121.147,
            "i_A": 0.000
        }
    ]
}

This is what I see in the log:

^[[37m[3/18/2022, 11:17:31 AM] ^[[39m^[[31mERROR LOADING PLUGIN homebridge-http-temperature:^[[39m                                       
^[[37m[3/18/2022, 11:17:31 AM] ^[[39m^[[31m/homebridge/node_modules/homebridge-http-temperature/index.js:2^[[39m                         
^[[31mimport request from "http";^[[39m                                                                                                  
^[[31m^^^^^^^[[39m                                                                                                                       
^[[31m^[[39m                                                                                                                             
^[[31mSyntaxError: Cannot use import statement outside a module^[[39m                                                                    
^[[31m    at Object.compileFunction (node:vm:352:18)^[[39m                                                                               
^[[31m    at wrapSafe (node:internal/modules/cjs/loader:1032:15)^[[39m                                                                   
^[[31m    at Module._compile (node:internal/modules/cjs/loader:1067:27)^[[39m                                                            
^[[31m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)^[[39m                                              
^[[31m    at Module.load (node:internal/modules/cjs/loader:981:32)^[[39m                                                                 
^[[31m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)^[[39m                                                       
^[[31m    at Module.require (node:internal/modules/cjs/loader:1005:19)^[[39m                                                             
^[[31m    at require (node:internal/modules/cjs/helpers:102:18)^[[39m                                                                    
^[[31m    at Plugin.load (/usr/local/lib/node_modules/homebridge/src/plugin.ts:197:93)^[[39m      
metbosch commented 2 years ago

Thanks for the feedback, I will try to take a look tomorrow. The issue is that I no longer use the homebridge, so I have to create a test env.

Jaume Bosch at 📲

El 18 mar 2022, a las 19:32, Michael Bierman @.***> escribió:

 O.K. so I manually updated the install. Here is what I have

  {
       "accessory": "HttpTemperature",
       "name": "Neurio",
       "manufacturer": "Neurio",
       "serial": "300",
       "url": "http://neurio.lan/current-sample",
       "http_method": "GET",
       "field_name": ".channels[1].p_W",
       "units": "F",
       "update_interval": 10000,
       "min_temp": 10,
       "max_temp": 10000,
       "debug": true,
       "auth": {
           "user": "X",
           "pass": "XXXX"
       }
   }

], Questions should these values be quoted?

"min_temp": 10, "max_temp": 10000, "update_interval": 10000, The overall result looks like

{ "sensorId": "0x0000C47F51019A27", "timestamp": "2022-03-18T18:25:38Z", "channels": [ { "type": "PHASE_A_CONSUMPTION", "ch": 1, "eImp_Ws": 74225753311, "eExp_Ws": 639931, "p_W": 399, "q_VAR": 28, "v_V": 121.144 }, { "type": "CONSUMPTION", "ch": 2, "eImp_Ws": 89193271933, "eExp_Ws": 96708, "p_W": 399, "q_VAR": 28, "v_V": 121.144 } ], "cts": [ { "ct": 1, "p_W": 399, "q_VAR": 28, "v_V": 121.144, "i_A": 3.704 }, { "ct": 2, "p_W": 242, "q_VAR": 2, "v_V": 121.106, "i_A": 2.130 }, { "ct": 3, "p_W": 0, "q_VAR": 0, "v_V": 0.258, "i_A": 0.000 }, { "ct": 4, "p_W": 0, "q_VAR": 0, "v_V": 121.147, "i_A": 0.000 } ] } This is what I see in the log:

^[[37m[3/18/2022, 11:17:31 AM] ^[[39m^[[31mERROR LOADING PLUGIN homebridge-http-temperature:^[[39m
^[[37m[3/18/2022, 11:17:31 AM] ^[[39m^[[31m/homebridge/node_modules/homebridge-http-temperature/index.js:2^[[39m
^[[31mimport request from "http";^[[39m
^[[31m^^^^^^^[[39m
^[[31m^[[39m
^[[31mSyntaxError: Cannot use import statement outside a module^[[39m
^[[31m at Object.compileFunction (node:vm:352:18)^[[39m
^[[31m at wrapSafe (node:internal/modules/cjs/loader:1032:15)^[[39m
^[[31m at Module._compile (node:internal/modules/cjs/loader:1067:27)^[[39m
^[[31m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)^[[39m
^[[31m at Module.load (node:internal/modules/cjs/loader:981:32)^[[39m
^[[31m at Function.Module._load (node:internal/modules/cjs/loader:822:12)^[[39m
^[[31m at Module.require (node:internal/modules/cjs/loader:1005:19)^[[39m
^[[31m at require (node:internal/modules/cjs/helpers:102:18)^[[39m
^[[31m at Plugin.load (/usr/local/lib/node_modules/homebridge/src/plugin.ts:197:93)^[[39m
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

metbosch commented 2 years ago

@mbierman Can you try again with the new code in master branch?

Regarding your config:

mbierman commented 2 years ago

Thank you! That is working perfectly except it is converting the watts from C to F because my homebridge is set to F. I suppose I can just hack that myself, but this is where I thought if there was a way to specify a different unit that did not convert it would be perfect. Note, I did not try the header yet. I'm not quite sure how that is supposed to work. Can you give an example?

metbosch commented 2 years ago

The F conversion is handled by the home app in ios, I don't know if you can change the units just for 1 device.

The headers example would be:

"accessories": [
  {
    "accessory": "HttpTemperature",
    "name": "Outside Temperature",
    "url": "http://IP/path/to/endpoint",
    "http_headers":  {
      "Content-Type": "application/json",
      "My-Header": "SECRET_TOKEN"
    }
  }
]
metbosch commented 2 years ago

@mbierman I'm going to publish the 0.10.0 version to npm now. Then, you would be able to test the plugin with the regular install methods.

mbierman commented 2 years ago

Thanks! Maybe I'll try putting a conversion in the plugin to take the value and convert it and report that value!

mbierman commented 2 years ago

That worked perfectly! When I have a chance, I'll try to make it more elegant. Right now I just changed the C>F conversion you already had. Thank you again!

metbosch commented 2 years ago

I think that the best approach would be to use a different kind of sensor, but I don't know which is the appropriate one...

mbierman commented 2 years ago

I don't know either. I looked at the list you sent and nothing seemed obvious. This used to work, but the author isn't maintaining it. https://github.com/homespun/homebridge-accessory-neurio

mbierman commented 2 years ago

I just noticed this.image

Any idea what the issue is?

metbosch commented 2 years ago

Try enabling the debug option to get some verbose prints

mbierman commented 2 years ago

So i changed the frequency to 3 minutes and it seems to be o.k..