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");
|
||||
|
||||
namespace OilTank {
|
||||
Sensor* buildRoomSensor(const char* id) {
|
||||
DeviceConfig* device = &DeviceConfig::create(id)
|
||||
.withName("Servers room")
|
||||
.withManufacturer("Atmel")
|
||||
.withModel("AtTiny85")
|
||||
.withArea("Basement")
|
||||
.withParent(gatewayDevice);
|
||||
return Builder<TemperatureSensor>::instance(id)
|
||||
.asDevice(device)
|
||||
.withValueTemplate("{{ value_json.sensor.temperature }}")
|
||||
.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 }}"})
|
||||
.build();
|
||||
}
|
||||
Sensor* buildRoomSensor(const char* id) {
|
||||
DeviceConfig* device = &DeviceConfig::create(id)
|
||||
.withName("Servers room")
|
||||
.withManufacturer("Atmel")
|
||||
.withModel("AtTiny85")
|
||||
.withArea("Basement")
|
||||
.withParent(gatewayDevice);
|
||||
return Builder<TemperatureSensor>::instance(id)
|
||||
.asDevice(device)
|
||||
.withValueTemplate("{{ value_json.sensor.temperature }}")
|
||||
.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 }}"})
|
||||
.build();
|
||||
}
|
||||
|
||||
Sensor* buildTankSensor(const char* id) {
|
||||
DeviceConfig* device = &DeviceConfig::create(id)
|
||||
.withName("Oil tank")
|
||||
.withManufacturer("Arduino")
|
||||
.withModel("Pro Mini")
|
||||
.withArea("Basement")
|
||||
.withParent(gatewayDevice);
|
||||
return Builder<Sensor>::instance(new Sensor{ "Level", id })
|
||||
.asDevice(device)
|
||||
.withUnitMeasure("%")
|
||||
Sensor* buildTankSensor(const char* id) {
|
||||
DeviceConfig* device = &DeviceConfig::create(id)
|
||||
.withName("Oil tank")
|
||||
.withManufacturer("Arduino")
|
||||
.withModel("Pro Mini")
|
||||
.withArea("Basement")
|
||||
.withParent(gatewayDevice);
|
||||
return Builder<Sensor>::instance(new Sensor{ "Level", id })
|
||||
.asDevice(device)
|
||||
.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)
|
||||
.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)
|
||||
.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();
|
||||
}
|
||||
.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 {
|
||||
@ -146,6 +144,6 @@ Command* commands[] = {
|
||||
};
|
||||
|
||||
Sensor* sensors[] = {
|
||||
OilTank::buildRoomSensor("4"),
|
||||
OilTank::buildTankSensor("7")
|
||||
buildRoomSensor("4"),
|
||||
buildTankSensor("7")
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user