Skip to content

Commit

Permalink
memory optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
luka6000 committed Nov 5, 2024
1 parent d989364 commit 944b2f7
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions tagtuner-atom-grove.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ esphome:
effect: HelloWorld
- delay: 1000ms
- light.turn_off: led1
- wait_until:
condition:
api.connected:
timeout: 20s
- text_sensor.template.publish:
id: status
state: "Ready"
Expand Down Expand Up @@ -197,6 +201,13 @@ light:
duration: 50ms

script:
- id: wait_input
then:
- delay: 3s
- text_sensor.template.publish:
id: status
state: "Waiting for input"

- id: led_blink
then:
- light.turn_on:
Expand Down Expand Up @@ -292,10 +303,8 @@ text_sensor:
condition:
lambda: 'return id(status).state != "Waiting for input";'
then:
- delay: 3s
- text_sensor.template.publish:
id: status
state: "Waiting for input"
- script.stop: wait_input
- script.execute: wait_input

sensor:
- platform: rotary_encoder
Expand Down Expand Up @@ -460,6 +469,10 @@ pn532_i2c:
- text_sensor.template.publish:
id: status
state: "Tag removed"
- wait_until:
condition:
api.connected:
timeout: 20s
- homeassistant.event:
event: esphome.tagtuner
data:
Expand All @@ -471,28 +484,20 @@ pn532_i2c:
- logger.log: "on_tag"
- text_sensor.template.publish:
id: status
state: "Tag read"
- text_sensor.template.publish:
id: status
state: !lambda 'return x;'
state: !lambda 'return "Tag "+x;'
- lambda: |-
id(playlist)="";
id(artist)="";
id(uri)="";
if (tag.has_ndef_message()) {
auto message = tag.get_ndef_message();
auto records = message->get_records();
for (auto &record : records) {
for (auto &record : tag.get_ndef_message()->get_records() ) {
std::string payload = record->get_payload();
std::string type = record->get_type();
std::string tag_artist = payload.substr(0, 7);
std::string tag_playlist = payload.substr(0, 9);
if ( tag_artist == "artist/" ) {
if ( payload.substr(0, 7) == "artist/" ) {
id(artist)=payload.substr(7);
}
else if ( tag_playlist == "playlist/" ) {
else if ( payload.substr(0, 9) == "playlist/" ) {
id(playlist)=payload.substr(9);
}
else if (type == "U" && payload.substr(0, 20) != "https://mb.senic.com" ) {
Expand All @@ -505,32 +510,36 @@ pn532_i2c:
condition:
lambda: 'return id(uri) == "" ;'
then:
- text_sensor.template.publish:
id: status
state: "Plain UID tag"
- homeassistant.tag_scanned: !lambda |-
ESP_LOGD("tagtuner", "No TagTuner NDEF, using UID");
return x;
- text_sensor.template.publish:
id: status
state: "Plain UID tag"
- homeassistant.tag_scanned: !lambda |-
ESP_LOGD("tagtuner", "No TagTuner NDEF, using UID");
return x;
else:
- text.set:
id: playlist_artist
value: !lambda |-
return id(artist);
- text.set:
id: playlist_info
value: !lambda |-
return id(playlist);
- text.set:
id: playlist_uri
value: !lambda |-
ESP_LOGD("tagtuner", "URI NDEF");
return id(uri);
- homeassistant.event:
event: esphome.tagtuner
data:
action: "tag_scanned"
uid: !lambda 'return x;'
uri: !lambda 'return id(uri);'
artist: !lambda 'return id(artist);'
playlist: !lambda 'return id(playlist);'
- wait_until:
condition:
api.connected:
timeout: 20s
- homeassistant.event:
event: esphome.tagtuner
data:
action: "tag_scanned"
uid: !lambda 'return x;'
uri: !lambda 'return id(uri);'
artist: !lambda 'return id(artist);'
playlist: !lambda 'return id(playlist);'
- text.set:
id: playlist_artist
value: !lambda |-
return id(artist);
- text.set:
id: playlist_info
value: !lambda |-
return id(playlist);
- text.set:
id: playlist_uri
value: !lambda |-
ESP_LOGD("tagtuner", "URI NDEF");
return id(uri);
- script.execute: led_blink

0 comments on commit 944b2f7

Please sign in to comment.