Jakubkuba9000 / homebridge-http-json-thermometer

Homebridge plugin designed for a web-based thermometer.
Apache License 2.0
0 stars 2 forks source link

Add Support For Humidity #1

Open ssmoss opened 10 months ago

ssmoss commented 10 months ago

Would it be possible to add support for humidity if the sensor can report both temperature and humidity? Thanks!

Jakubkuba9000 commented 10 months ago

Hi @ssmoss

I think it would be possible.

Could you please specify how the JSON file looks? Are both values in the same JSON file or are there 2 JSON files?

Thank you for your suggestion!

ssmoss commented 10 months ago

So I think the existing format is great and one additional key could be added. Currently it looks like this:

{
    "platform": "HttpJsonThermometer",
    "thermometers": [
        {
            "thermometerName": "Terrarium thermometer",
            "httpRoute": "http://ipaddress/status/",
            "updateInterval": 60,
            "jsonName": "temp",
            "calibration": 0.16,
            "manufacturer": "Default-Manufacturer",
            "model": "Default-Model",
            "serial": "Default-Serial"
        }
    ]
}

My proposal would be to add an additional top level key:

{
    "platform": "HttpJsonThermometer",
    "thermometers": [
        {
            "thermometerName": "Terrarium thermometer",
            "httpRoute": "http://ipaddress/status/",
            "updateInterval": 60,
            "jsonName": "temp",
            "calibration": 0.16,
            "manufacturer": "Default-Manufacturer",
            "model": "Default-Model",
            "serial": "Default-Serial"
        }
    ],
    "hygrometers": [
        {
            "hygrometerName": "Terrarium hygrometers",
            "httpRoute": "http://ipaddress/status/",
            "updateInterval": 60,
            "jsonName": "hygrometers",
            "calibration": 0.16,
            "manufacturer": "Default-Manufacturer",
            "model": "Default-Model",
            "serial": "Default-Serial"
        }
    ]
}
ssmoss commented 10 months ago

As I was thinking about what this should look like it also got me thinking if a second format could be supported as well. Currently the plural form the key expects a list of object were each object is a sensor. This means that for n sensors the code would need to make n http requests. Would also be possible to support using the singular form of the key as shown below:

{
    "platform": "HttpJsonThermometer",
    "thermometer":  {
        "httpRoute": "http://ipaddress/status/thermometer",
        "updateInterval": 60,
    },
    "hygrometer": {
        "httpRoute": "http://ipaddress/status/hygrometer",
        "updateInterval": 60,
    }
}

The http://ipaddress/status/thermometer endpoint would return:

[
    {
        "thermometerName": "Terrarium thermometer",
        "jsonName": "temp",
        "calibration": 0.16,
        "manufacturer": "Default-Manufacturer",
        "model": "Default-Model",
        "serial": "Default-Serial"
    }
]

The http://ipaddress/status/hygrometer endpoint would return:

[
    {
        "hygrometerName": "Terrarium hygrometers",
        "jsonName": "hygrometers",
        "calibration": 0.16,
        "manufacturer": "Default-Manufacturer",
        "model": "Default-Model",
        "serial": "Default-Serial"
    }
]

This would allow for a single request to return an aggregated list of sensors.

Another option might be something like this:

{
    "platform": "HttpJsonThermometer",
    "thermometers": [
        {
            "thermometerName": "Terrarium thermometer",
            "httpRoute": "http://ipaddress/status/temp-1",
            "updateInterval": 60,
            "jsonName": "temp",
            "calibration": 0.16,
            "manufacturer": "Default-Manufacturer",
            "model": "Default-Model",
            "serial": "Default-Serial"
        },
        {
            "httpRoute": "http://ipaddress/status/temp-many",
            "updateInterval": 60,
            "multi": true
        }
    ],
    "hygrometers": [
        {
            "hygrometerName": "Terrarium hygrometers",
            "httpRoute": "http://ipaddress/status/hygrometers-1",
            "updateInterval": 60,
            "jsonName": "hygrometers",
            "calibration": 0.16,
            "manufacturer": "Default-Manufacturer",
            "model": "Default-Model",
            "serial": "Default-Serial"
        },
        {
            "httpRoute": "http://ipaddress/status/hygrometers-many",
            "updateInterval": 60,
            "multi": true
        }
    ]
}

When multi or a key of some other name is set to true the json response contains a list of sensors?

Jakubkuba9000 commented 10 months ago

Hi @ssmoss

I was thinking what a JSON file looks like on the device side not a JSON config file, but never mind.

As for your first comment, this could definitely be done, so it would work as 2 separate devices, one for temperature and one for humidity. That said, it needs to make 2 http requests.

As for your second comment, I honestly don't really understand what you mean. What you wrote is a JSON config file and all the information for the device needs to be described there, not referenced via an http request. Through the http request the plugin takes only the temperature values. This means that the http://ipaddress/status/ would for example return JSON file like this:

{
 "temp": "24.88",
 "temp2": "24.06",
 "temp3": "23.75"
}

It is true that to retrieve all these 3 values, 3 http requests must be made. This may be unnecessary when it is on the same URL. So do I understand correctly that you want the code to make one http request to get multiple values to multiple sensors?

Anyway, I'll think about it, because it's an interesting idea. For now I would prefer the solution described in your first comment. When I have time, I'll get to work on it.

Thank you.

ssmoss commented 10 months ago

Yay, I can't wait for this! And I understand that for different sensor types there would be an expectation of needing another request.

So do I understand correctly that you want the code to make one http request to get multiple values to multiple sensors?

Sorry, sounds like I wasn't as clear as I could have been. Yes that is the short version of what I am asking about.

To give some background I have a database view that contains the current values for a bunch of temperature sensors I have. I was hoping I could make a single request and return a json array of sensor objects in the format required by the plugin. If it doesn't make sense or your don't like it, the current format works perfect as well.

Thanks again for the quick reply!