Code Monkey home page Code Monkey logo

Comments (2)

huizebruin avatar huizebruin commented on August 25, 2024

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: ""
    set_action:
      lambda: id(total_water_pulses) = x * 1000;  
      ```
      
 what did you else ?

from s0tool.

stingone avatar stingone commented on August 25, 2024

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: ""
    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: ""
    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: ""
      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: ""
    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

from s0tool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.