Fixed esphome definition
This commit is contained in:
@@ -8,7 +8,7 @@ esphome:
|
||||
on_boot:
|
||||
- priority: 300
|
||||
then:
|
||||
- dfplayer.set_volume: 15
|
||||
- dfplayer.set_volume: 10
|
||||
|
||||
esp8266:
|
||||
board: d1_mini_lite
|
||||
@@ -47,31 +47,29 @@ pn532_i2c:
|
||||
update_interval: 1s
|
||||
on_tag:
|
||||
then:
|
||||
- !lambda |-
|
||||
if (tag.has_ndef_message()) {
|
||||
const auto &message = tag.get_ndef_message();
|
||||
const auto &records = message->get_records();
|
||||
for (const auto &record : records) {
|
||||
if (record->get_type().c_str()[0] != 'T') {
|
||||
ESP_LOGD("Fabula", " Ignoring non-text record %s", record->get_payload().c_str());
|
||||
continue;
|
||||
}
|
||||
ESP_LOGD("Fabula", " Found record %s in tag, try to convert to int", record->get_payload().c_str());
|
||||
// Note: exception handling is disabled in ESPHome: the following line may crash the microcontroller if a tag with a textual record if scanned
|
||||
int folderId = std::stoi(record->get_payload());
|
||||
ESP_LOGD("Fabula", " Found valid record in tag: playing folder %d", folderId);
|
||||
id(current_folder) = folderId;
|
||||
return folderId;
|
||||
}
|
||||
}
|
||||
ESP_LOGD("Fabula", " No valid record found in tag. Please add a text field containing the folder number, e.g. 001");
|
||||
id(current_folder) = 0;
|
||||
return 0;
|
||||
# - logger.log:
|
||||
# format: "NFC Tag found: %s"
|
||||
# args: [ 'tag.get_ndef_message()->get_records()[0]->get_payload().c_str()' ]
|
||||
- dfplayer.play_folder:
|
||||
folder:
|
||||
loop: True
|
||||
# Crashes somewhere here in the lambda
|
||||
folder: !lambda |-
|
||||
if (tag.has_ndef_message()) {
|
||||
const auto &message = tag.get_ndef_message();
|
||||
const auto &records = message->get_records();
|
||||
for (const auto &record : records) {
|
||||
if (record->get_type().c_str()[0] != 'T') {
|
||||
ESP_LOGD("Fabula", " Ignoring non-text record %s", record->get_payload().c_str());
|
||||
continue;
|
||||
}
|
||||
ESP_LOGD("Fabula", " Found record %s in tag, try to convert to int", record->get_payload().c_str());
|
||||
// Note: exception handling is disabled in ESPHome: the following line may crash the microcontroller if a tag with a textual record if scanned
|
||||
int folderId = std::stoi(record->get_payload());
|
||||
ESP_LOGD("Fabula", " Found valid record in tag: playing folder %d", folderId);
|
||||
id(current_folder) = folderId;
|
||||
return folderId;
|
||||
}
|
||||
}
|
||||
ESP_LOGD("Fabula", " No valid record found in tag. Please add a text field containing the folder number, e.g. 001");
|
||||
id(current_folder) = 0;
|
||||
return 0;
|
||||
on_tag_removed:
|
||||
then:
|
||||
- logger.log: "NFC Tag removed"
|
||||
|
||||
Reference in New Issue
Block a user