-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add initial meter total in ESPhome #156
Comments
Hello @stingone When i add this to my esphome config it stays on 0.001 and i used a lot of water today. number:
- name: Initiële meterstand m3
platform: template
id: initial_water_value
device_class: water
min_value: 0.001
max_value: 100000
step: 0.001
entity_category: config
icon: mdi:water
unit_of_measurement: "m³"
set_action:
lambda: id(total_water_pulses) = x * 1000;
```
what did you else ? |
You should get an extra field called Initiële meterstand m3. You can than fill-in once the initiele meterstand and hit enter. It then updates the total total_water_pulses once to the entered value. After that the field returns to 0. See my current code based on your code. esphome:
name: ${name}
name_add_mac_suffix: false
substitutions:
name: water-sensor
device_description: ${name} gemaakt door huizebruin.nl versie ${vdate}.
vdate: "v23.12.34"
date: "21-12-2023"
esp8266:
board: d1_mini
preferences:
flash_write_interval: 120min
improv_serial:
web_server:
port: 80
# Enable logging
logger:
level: INFO
esp8266_store_log_strings_in_flash: false
ota:
time:
- platform: homeassistant
id: time_homeassistant
on_time_sync:
- component.update: S0tool_uptime_timestamp
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Water-Sensor Fallback Hotspot"
password: "BRqxU0cJnwJg"
captive_portal:
# Delen en bewerken mag maar laat deze eerste regels staan.
# Bron : https://www.huizebruin.nl
# Bron File : https://github.com/huizebruin/s0tool/tree/main/esphome
# © Huizebruin.nl
# # ⬇ Enable Home Assistant API ⬇ #
api:
services:
- service: meterstand_water
variables:
meter_value: float
then:
- globals.set:
id: initial_water_usage
value: !lambda "return ( meter_value - (id(total_water_pulses)) * atof(id(Select_pulse_water).state.c_str()) ) ;"
- globals.set:
id: total_water_pulses
value: "0"
globals:
- id: initial_water_usage
type: float
restore_value: yes
initial_value: '0'
- id: total_water_pulses
type: int
restore_value: yes
select:
# ⬇ water per m3 rate ⬇ #
- platform: template
name: "Pulsrate water per m3"
id: Select_pulse_water
optimistic: true
options:
- "0.0001"
- "0.0005"
- "0.001"
- "0.01"
- "0.1"
initial_option: "0.001"
restore_value: yes
entity_category: config
on_value:
then:
- logger.log:
format: "Chosen option: %s "
args: ["x.c_str()"]
number:
- name: Initiële meterstand m3
platform: template
id: initial_water_value
device_class: water
min_value: 0
max_value: 100000
step: 0.001
entity_category: config
icon: mdi:water
unit_of_measurement: "m³"
set_action:
- lambda: id(total_water_pulses) = x * 1000;
text_sensor:
- platform: template
name: "s0tool_versie"
id: s0tool_versie
icon: 'mdi:alpha-v-circle-outline'
update_interval: 6h
entity_category: diagnostic
lambda: |-
return {"${vdate}"};
- platform: wifi_info
ip_address:
name: "${name} IP-adres"
id: s0tool_ip_adres
icon: mdi:ip-network
mac_address:
name: "${name} Mac-adres"
id: s0tool_mac_adres
icon: mdi:folder-key-network-outline
# restart button #
button:
- platform: restart
name: "${name} Restart device"
entity_category: diagnostic
# Factory Reset Switch from ESPHome v2022.09
- platform: factory_reset
name: "Restart with Factory Default Settings"
entity_category: diagnostic
# safe mode button
- platform: safe_mode
name: "Safe Mode"
entity_category: diagnostic
#------------------------# Watermeter #------------------------#
binary_sensor:
- platform: gpio
id: water_sensor_status
name: "Water sensor status"
internal: False
pin:
number: D5
allow_other_uses: true
inverted: true
on_press:
- then:
lambda: id(total_water_pulses) += 1;
sensor:
#------------------------# Watermeter #------------------------#
# ⬇ watermeter pulsen ⬇ #
- platform: pulse_meter
internal_filter_mode: "PULSE"
internal_filter: 50ms
pin:
number: D5
allow_other_uses: true
mode:
input: true
pullup: true
id: watermeter_flow
name: "Watermeter flow"
state_class: measurement
unit_of_measurement: "l/min"
accuracy_decimals: 1
icon: "mdi:water-pump"
filters:
lambda: return x * atof(id(Select_pulse_water).state.c_str()) * 1000;
# ⬇ Totaal watermeter ⬇ #
total:
id: sensor_pulse_meter_total
name: "Watermeter Totaal"
unit_of_measurement: "m³"
state_class: total_increasing
device_class: water
icon: mdi:water
accuracy_decimals: 3
filters:
- multiply: 0.001
# ⬇ Watermeter stand bij benadering ⬇ #
- platform: template
id: watermeter_total
name: "Watermeter Stand"
state_class: "total_increasing"
icon: mdi:water
unit_of_measurement: "m³"
update_interval: 30s
accuracy_decimals: 3
lambda: return id(initial_water_usage) + (id(total_water_pulses) * atof(id(Select_pulse_water).state.c_str()));
# ⬇ Waterpulses only web interface for debugging ⬇ #
- platform: template
id: watermeter_flow_totaal
name: "Watermeter flow Totaal"
state_class: "total_increasing"
accuracy_decimals: 0
lambda: return id(total_water_pulses);
internal: False
#------------------------# sensoren #------------------------#
- platform: uptime
id: S0tool_uptime
- platform: template
id: S0tool_uptime_timestamp
name: "${name} online sinds"
device_class: "timestamp"
accuracy_decimals: 0
update_interval: never
icon: 'mdi:clock-start'
entity_category: diagnostic
lambda: |-
static float timestamp = (
id(time_homeassistant).utcnow().timestamp - id(S0tool_uptime).state
);
return timestamp;
# ⬇ versie verbinding informatie sensoren voor in ha ⬇ #
# WiFi signal
- platform: wifi_signal
name: "${name} - WiFi Signal"
update_interval: 120s |
* Ad minimal version ESPHome to 2024.2.0. * Update s0tool code to v24.02.23.35 (vyear-month-day-version) * Use the standard esp8266 standard to the config. * Updated the Package folder and remove of the sensor folder see [readme file ](https://github.com/huizebruin/s0tool) * Update readme file. * Update Flash page. * Add a sensor #156 default to hidden. * Sensor factory reset and safeboot also hidden by default.
Could you add the option to set the initial water meter value from the meter itself into your code?
i used the code below and it works fine.
`number:
platform: template
id: initial_water_value
device_class: water
min_value: 0
max_value: 100000
step: 0.001
entity_category: config
icon: mdi:water
unit_of_measurement: "m³"
set_action:
The text was updated successfully, but these errors were encountered: