Cześć. Nie taki już nowy w temacie ale utknąłem na użyciu Global Variables w ESPHome. Chcę w prosty sposób zliczać obroty podajnika ślimakowego w celu obliczenia zużycia ekogroszku na dobę. Sprzętowo wszystko działa.
Konfiguracja
# tutaj wszystko gra i buczy
globals:
- id: co_tank_rotary_counter
type: int
restore_value: yes
initial_value: '0'
binary_sensor:
- platform: gpio
id: co_tank_rotary_meter
name: "Co Tank Rotary Meter"
pin:
number: D4
mode: INPUT_PULLUP
filters:
- delayed_on: 300ms
- delayed_off: 300ms
on_press:
then:
- lambda: |-
id(co_tank_rotary_counter) += 1;
# chce teraz wyświetlić sobie wartości w oparciu o tą zmienną globalną ale
# pokonało mnie konwertowanie wartości int na string :confused:
text_sensor:
- platform: template
name: "Coal Conspumption"
id: coal_consumption
icon: "mdi:water-boiler"
lambda: |-
return printf("Consumption: %d", id(co_tank_rotary_counter));
update_interval: 5s
filters:
- append: 'kg/day'
dostaję błąd konwersji int na string
error: could not convert 'printf(((const char*)"Consumption: %d"), co_tank_rotary_counter->esphome::globals::RestoringGlobalsComponent<int>::value())' from 'int' to 'esphome::optional<std::__cxx11::basic_string<char> >'
123 | return printf("Consumption: %d", id(co_tank_rotary_counter));
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| int
*** [.pioenvs/watertermstat/src/main.cpp.o] Error 1
próbowałem już wiele patentów z internetów ale kurcze utyka w podobnym miejscu. Ma ktoś z Was pomysł jak rozwiązać problem z konwersją.
P.S.
Do tego patentu nie nadaje się pulse_meter ani pulse_counter.