no need to have OilTank namespace since it has only one sensor
This commit is contained in:
parent
ff53fa9831
commit
7258ab9b56
@ -15,47 +15,45 @@ unordered_map<string, Ha::Switch*> p1Switches;
|
|||||||
|
|
||||||
auto gatewayDevice = &DeviceConfig::create(MAIN_DEVICE_ID).withName("RC Gateway").withManufacturer("Adafruit").withModel("Huzzah Esp8266");
|
auto gatewayDevice = &DeviceConfig::create(MAIN_DEVICE_ID).withName("RC Gateway").withManufacturer("Adafruit").withModel("Huzzah Esp8266");
|
||||||
|
|
||||||
namespace OilTank {
|
Sensor* buildRoomSensor(const char* id) {
|
||||||
Sensor* buildRoomSensor(const char* id) {
|
DeviceConfig* device = &DeviceConfig::create(id)
|
||||||
DeviceConfig* device = &DeviceConfig::create(id)
|
.withName("Servers room")
|
||||||
.withName("Servers room")
|
.withManufacturer("Atmel")
|
||||||
.withManufacturer("Atmel")
|
.withModel("AtTiny85")
|
||||||
.withModel("AtTiny85")
|
.withArea("Basement")
|
||||||
.withArea("Basement")
|
.withParent(gatewayDevice);
|
||||||
.withParent(gatewayDevice);
|
return Builder<TemperatureSensor>::instance(id)
|
||||||
return Builder<TemperatureSensor>::instance(id)
|
.asDevice(device)
|
||||||
.asDevice(device)
|
.withValueTemplate("{{ value_json.sensor.temperature }}")
|
||||||
.withValueTemplate("{{ value_json.sensor.temperature }}")
|
.addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})
|
||||||
.addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})
|
.addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-2.5)|round(2)*100/2)|int }}"})
|
||||||
.addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-2.5)|round(2)*100/2)|int }}"})
|
.build();
|
||||||
.build();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Sensor* buildTankSensor(const char* id) {
|
Sensor* buildTankSensor(const char* id) {
|
||||||
DeviceConfig* device = &DeviceConfig::create(id)
|
DeviceConfig* device = &DeviceConfig::create(id)
|
||||||
.withName("Oil tank")
|
.withName("Oil tank")
|
||||||
.withManufacturer("Arduino")
|
.withManufacturer("Arduino")
|
||||||
.withModel("Pro Mini")
|
.withModel("Pro Mini")
|
||||||
.withArea("Basement")
|
.withArea("Basement")
|
||||||
.withParent(gatewayDevice);
|
.withParent(gatewayDevice);
|
||||||
return Builder<Sensor>::instance(new Sensor{ "Level", id })
|
return Builder<Sensor>::instance(new Sensor{ "Level", id })
|
||||||
.asDevice(device)
|
.asDevice(device)
|
||||||
.withUnitMeasure("%")
|
.withUnitMeasure("%")
|
||||||
|
.withSensorStateClass(MEASUREMENT)
|
||||||
|
.withIcon("mdi:hydraulic-oil-level")
|
||||||
|
.withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}")
|
||||||
|
.addSecondary(
|
||||||
|
Builder<Sensor>::instance(new Sensor{ "Depth", id })
|
||||||
|
.withDeviceClass("distance")
|
||||||
|
.withUnitMeasure("cm")
|
||||||
.withSensorStateClass(MEASUREMENT)
|
.withSensorStateClass(MEASUREMENT)
|
||||||
.withIcon("mdi:hydraulic-oil-level")
|
.withValueTemplate("{{ value_json.sensor.value }}")
|
||||||
.withValueTemplate("{{ 100 - ((value_json.sensor.value-12)|float*100/120)|round(2) }}")
|
.build()
|
||||||
.addSecondary(
|
)
|
||||||
Builder<Sensor>::instance(new Sensor{ "Depth", id })
|
.addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})
|
||||||
.withDeviceClass("distance")
|
.addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-4.8)|round(2)*100/1.6)|int }}"})
|
||||||
.withUnitMeasure("cm")
|
.build();
|
||||||
.withSensorStateClass(MEASUREMENT)
|
|
||||||
.withValueTemplate("{{ value_json.sensor.value }}")
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.addDiagnostic(new VoltageSensor{id, "Battery voltage", "{{ value_json.sensor.diagnostic.voltage }}"})
|
|
||||||
.addDiagnostic(new BatterySensor{id, "Battery level", "{{ ((value_json.sensor.diagnostic.voltage|float-4.8)|round(2)*100/1.6)|int }}"})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PollinSwitch : Switch {
|
struct PollinSwitch : Switch {
|
||||||
@ -146,6 +144,6 @@ Command* commands[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Sensor* sensors[] = {
|
Sensor* sensors[] = {
|
||||||
OilTank::buildRoomSensor("4"),
|
buildRoomSensor("4"),
|
||||||
OilTank::buildTankSensor("7")
|
buildTankSensor("7")
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user