Hi there,
In my esphome script I try to get the value of a home assistant helper, change it on device and send the calculated value back to home assistant.
In this case a have a relay with pumps attached on it. Every time I activate the relay I take the starting time. On turn off I fetch the water level (mentioned helper), calculate the consumption and I want to write back the new calculated water level back to home assistant. When I refill the water tank I want to reset that helper back to the new level.
What I did so far:
-
I configured a helper in home assistant
-
Here my esphome yml
globals:
- id: water_consumption_per_sec_in_ml
type: int
# 23,2 p/sec
initial_value: '24'
- id: pump_1_start_time
type: time_t
time:
- platform: homeassistant
id: ha_time
timezone: Europe/Berlin
switch:
- platform: gpio
id: pump_1
name: "Pumpe 1"
pin:
number: 26
mode: OUTPUT
inverted: true
on_turn_on:
lambda: |-
id(pump_1_start_time) = id(ha_time).now().timestamp;
on_turn_off:
lambda: |-
int consumption = (id(ha_time).now().timestamp - id(pump_1_start_time)) * id(water_consumption_per_sec_in_ml);
int waterLevel = id(water_level_tank_1).state - consumption;
id(water_level_tank_1).publish_state(waterLevel);
sensor:
- platform: homeassistant
id: water_level_tank_1
entity_id: input_number.water_level_tank_1
The value on home assistant backend doesn’t change after publish_state. So my question is: Is this two way binding possible and how could I solve this issue?
Best regards
i7i5