-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
639 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: PlatformIO CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache/pip | ||
~/.platformio/.cache | ||
key: ${{ runner.os }}-pio | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
- name: Install PlatformIO Core | ||
run: pip install --upgrade platformio | ||
|
||
- name: Build PlatformIO Project wemos d1 mini | ||
run: pio run --project-dir sw/platformio --environment d1_mini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[env:d1_mini] | ||
platform = espressif8266 | ||
board = d1_mini | ||
framework = arduino | ||
lib_deps = | ||
bblanchon/ArduinoJson@^7.0.2 | ||
alanswx/ESPAsyncWiFiManager | ||
ottowinter/ESPAsyncWebServer-esphome@^3.1.0 | ||
knolleary/PubSubClient@^2.8 | ||
vshymanskyy/Preferences@^2.1.0 | ||
adafruit/Adafruit ADS1X15@^2.5.0 | ||
monitor_speed = 115200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
|
||
|
||
#include <Arduino.h> | ||
#include <ArduinoJson.h> | ||
#include "ha_discovery.h" | ||
|
||
HaDiscovery::HaDiscovery(String stateTopic) { | ||
_stateTopic = stateTopic; | ||
setDeviceInfo("NA", "NA", "NA"); | ||
} | ||
|
||
void HaDiscovery::setDeviceInfo(String serialNumber, String hw_version, String sw_version) { | ||
_devDoc["ids"] = serialNumber; //identifiers | ||
_devDoc["mf"] = "Sham(Sensirion)"; //manufacturer | ||
_devDoc["mdl"] = "SEN55"; //model | ||
_devDoc["name"] = "Sensirion SEN55"; | ||
_devDoc["hw"] = hw_version; //hw_version | ||
_devDoc["sw"] = sw_version; //sw_version | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicPm1p0() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/pm1p0/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTPm1p0DiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
|
||
doc["name"] = "Env " + String(sensorNumber) + " Pm1p0"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = "μg/mᵌ"; | ||
doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.pm1p0|default(0) }}"; | ||
doc["uniq_id"] = String(ESP.getChipId()) + "_pm1p0"; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicPm2p5() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/pm2p5/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTPm2p5DiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " Pm2p5"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = "μg/mᵌ"; | ||
doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.pm2p5|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_pm2p5"; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicPm4p0() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/pm4p0/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTPm4p0DiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " Pm4p0"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = "μg/mᵌ"; | ||
doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.pm4p0|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_pm4p0";; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicPm10p0() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/pm10p0/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTPm10p0DiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " Pm10p0"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = "μg/mᵌ"; | ||
doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.pm10p0|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_pm10p0";; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicTemperature() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/temperature/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTTemperatureDiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " Temperature"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = "⁰C"; | ||
doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.temperature|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_temp";; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicHumidity() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/humidity/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTHumidityDiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " Humidity"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = "%RH"; | ||
doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.humidity|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_humid"; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicVocindex() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/vocindex/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTVocIndexDiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " VocIndex"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = ""; | ||
// doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.vocIndex|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_voci"; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} | ||
|
||
String HaDiscovery::getDiscoveryTopicNoxindex() { | ||
int sensorNumber = ESP.getChipId(); | ||
return "homeassistant/sensor/env_sensor_" + String(sensorNumber) + "/noxindex/config"; | ||
} | ||
|
||
JsonDocument HaDiscovery::getMQTTNoxIndexDiscoveryMsg() { | ||
// My numeric sensor ID, you can change this to whatever suits your needs | ||
int sensorNumber = ESP.getChipId(); | ||
JsonDocument doc; | ||
|
||
doc["name"] = "Env " + String(sensorNumber) + " NoxIndex"; | ||
doc["stat_t"] = _stateTopic; | ||
doc["unit_of_meas"] = ""; | ||
// doc["sug_dsp_prc"] = 2; // 'suggested_display_precision', | ||
doc["frc_upd"] = true; | ||
doc["val_tpl"] = "{{ value_json.noxIndex|default(0) }}"; | ||
|
||
doc["uniq_id"] = String(ESP.getChipId()) + "_noxi";; | ||
doc["device"] = _devDoc; | ||
|
||
return doc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef HA_DISCOVERY_H | ||
#define HA_DISCOVERY_H | ||
#include <Arduino.h> | ||
#include <ArduinoJson.h> | ||
|
||
|
||
class HaDiscovery { | ||
public: | ||
HaDiscovery(String stateTopic); | ||
JsonDocument getMQTTPm1p0DiscoveryMsg(); | ||
JsonDocument getMQTTPm2p5DiscoveryMsg(); | ||
JsonDocument getMQTTPm4p0DiscoveryMsg(); | ||
JsonDocument getMQTTPm10p0DiscoveryMsg(); | ||
JsonDocument getMQTTTemperatureDiscoveryMsg(); | ||
JsonDocument getMQTTHumidityDiscoveryMsg(); | ||
JsonDocument getMQTTVocIndexDiscoveryMsg(); | ||
JsonDocument getMQTTNoxIndexDiscoveryMsg(); | ||
|
||
String getDiscoveryTopicPm1p0(); | ||
String getDiscoveryTopicPm2p5(); | ||
String getDiscoveryTopicPm4p0(); | ||
String getDiscoveryTopicPm10p0(); | ||
String getDiscoveryTopicTemperature(); | ||
String getDiscoveryTopicHumidity(); | ||
String getDiscoveryTopicVocindex(); | ||
String getDiscoveryTopicNoxindex(); | ||
|
||
void setDeviceInfo(String serialNumber, String hw_version, String sw_version); | ||
private: | ||
|
||
String _stateTopic; | ||
JsonDocument _devDoc; | ||
|
||
}; | ||
#endif | ||
|
||
|
||
|
||
|
Oops, something went wrong.