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

Want to know more about this plugin #1

Closed jaysettle closed 7 years ago

jaysettle commented 8 years ago

Hi I found this interesting but am wondering if you have a link to the hardware setup and possible the arduino code you're running there.

Also wondering is the temperature retrieved when Siri is asked for it? Is that how it works? Thanks.

metbosch commented 7 years ago

Hi, The HW setup is very easy, you can find several examples online depending on your temperature sensor (for example: http://4.bp.blogspot.com/-75ghh9AcZg0/U7ErGqBW61I/AAAAAAAADdc/YCWD5ra7rNY/s1600/temperature-humidity-arduino-chiosz1.jpg). What I really have is a Arduino D1 board with a DHT22 and a relay board. It allows me to control some lights in a room and get the temperature in the room. I'm planning to do a general sketch to support different devices base on my current code. I will let you know if I finally upload it.

About Siri, ios9 don't have a built-in capability to manage homekit devices but it seems to be included in ios10 (http://www.macrumors.com/2016/06/23/home-app-in-ios-10/). For now, I'm using the Inteon+ app (https://itunes.apple.com/es/app/insteon+/id919270334?mt=8) to manage the devices in my home.

paulobriennz commented 7 years ago

Hi, thanks for the plugin, works great! I am interested to get similar information, but for power consumption instead of temperature. I had a look at your code, but don't quite understand the architecture of the plugin language enough... if I wanted to do exactly the same method of polling but get the value as kw (Power) instead of degrees Celsius (Temperature), what would I change? I'm trying to figure out where the plugin lets homebridge know it does temperature.. could this be changed to any value?

metbosch commented 7 years ago

Hi, I'm not sure if Homebridge supports power consumption devices (The supported types should be here: https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js). About what you need to change, I have another repo for an humidity sensor (https://github.com/metbosch/homebridge-http-temperature/blob/master/index.js) if you compare both index.js files you will see the small changes needed :)

ghost commented 7 years ago

Hi! great work! Can u tell how to add more then one sensor? I want to add about 3-5 temperature sensors.

metbosch commented 7 years ago

It should be as simple as instantiate several accessories in your config.json. Like that:

"accessories": [
     {
         "accessory": "HttpTemperature",
         "name": "Sensor 1",
         "url": "http://192.168.1.210/temperature?format=json",
         "http_method": "GET"
     },{
         "accessory": "HttpTemperature",
         "name": "Sensor 2",
         "url": "http://192.168.1.211/temperature?format=json",
         "http_method": "GET"
     },{
         "accessory": "HttpTemperature",
         "name": "Sensor 3.1",
         "url": "http://192.168.1.212/temperature1?format=json",
         "http_method": "GET"
     },{
         "accessory": "HttpTemperature",
         "name": "Sensor 3.2",
         "url": "http://192.168.1.212/temperature2?format=json",
         "http_method": "GET"
     }
 ]

Note that one enpoind can have several temperature sensors, you only need to provide different URLs to read the data from each one.

ghost commented 7 years ago

Thanks for reply. What type of result should return the http server? Int or float? or result may be mixed?

metbosch commented 7 years ago

Hi, I don't tested how does it work with integer values but it should work without problems. The plugin only checks that the received value in the JSON is a Javascript number (http://www.w3schools.com/jsref/jsref_isnan.asp).

tamasharasztosi commented 7 years ago

Hey! I would like to get latest data from thingspeak but its json gives a format like this: request: https://api.thingspeak.com/channels/CHANNEL_NUMBER/field/1/last.json {"created_at":"2017-03-01T19:20:04Z","entry_id":29,"field1":"24.48"}

Could you help me out what should i modify to make it work?

metbosch commented 7 years ago

@tamasharasztosi Hi, it's very simple. You only have to create your own plugin version. The temperature is parsed in the following line (45, currently):

value = JSON.parse(body).temperature;

According to the JSON is your comment, you want to get the value in field1, so the line will be:

value = JSON.parse(body).field1;
xomanuel commented 7 years ago

@metbosch Hi, im not getting temperature from thingspeak, i already change this:

value = JSON.parse(body).field1;

this is my cofig:

{ "accessory": "HttpTemperature", "name": "DHT 11", "url": "http://api.thingspeak.com/channels/101216/field/1/last.json", "http_method": "GET"

     }],
metbosch commented 7 years ago

Which error do you have? Have you tried to output the parsed value? I will try to get a look as soon as I can. In the midtime, you can try:

value = JSON.parse(body).field1;
console.log(value);
metbosch commented 7 years ago

Hi @xomanuel,

I fixed the issue in 3612739ee6f9376508c7092bf8fd2dedeea19d2a. In addition, now you can define the field which value will be used from the incoming response.

Thank you!