The arest sensor platform allows you to get all data from your devices (like Arduinos with a ethernet/wifi connection, the ESP8266, and the Raspberry Pi) running the aREST RESTful framework.
To use your aREST enabled device in your installation, add the following to your configuration.yaml file:
123456789
# Example configuration.yaml entrysensor:platform:arestresource:http://IP_ADDRESSmonitored_variables:-name:temperatureunit:'°C'-name:humidityunit:'%'
Configuration variables:
resource (Required): IP address and schema of the device that is exposing an aREST API, e.g. http://192.168.1.10.
monitored_variables array:
name (Required): The name of the variable you wish to monitor.
unit (Optional): Defines the units of measurement of the sensor, if any.
The variables in the monitored_variables array must be available in the response of the device. As a starting point you find below a sketch for the Arduino device family. There are two variables (temperature and humidity) which will act as endpoints.
/* This modified sketch is based on the Ethernet example of the aREST (http://arest.io/) library.*/// Libraries#include <SPI.h>#include <Ethernet.h>#include <aREST.h>#include <avr/wdt.h>// Device settingschar*deviceId="sensor02";char*deviceName="livingroom";bytedeviceMac[]={0x20,0xD5,0xD3,0x03,0xFE,0x31};IPAddressdeviceIp(192,168,1,12);EthernetServerserver(80);aRESTrest=aREST();// Variables to be exposed to the APIinttemperature;inthumidity;voidsetup(void){Serial.begin(57600);// Init variables and expose them to REST APItemperature=0;humidity=0;rest.variable("temperature",&temperature);rest.variable("humidity",&humidity);// Give name and ID to devicerest.set_id(deviceId);rest.set_name(deviceName);Ethernet.begin(deviceMac,deviceIp);server.begin();Serial.print("Sensor is ready...");// Start watchdogwdt_enable(WDTO_4S);}voidloop(){EthernetClientclient=server.available();rest.handle(client);wdt_reset();// Replace this with your actual sensor readings, like// temperature = (((analogRead(A0) * 5.0) / 1024) - 0.5) * 10;temperature=random(400);humidity=random(600);delay(500);}