Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. ioBroker Allgemein
  4. esphome Zähler über mqtt lesen und schreiben

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.8k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.2k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    3.2k

esphome Zähler über mqtt lesen und schreiben

Scheduled Pinned Locked Moved ioBroker Allgemein
2 Posts 1 Posters 444 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bastl90
    wrote on last edited by
    #1

    Hallo zusammen,
    ich habe folgendes vor: ich möchte einen Zähler für Impulse.
    Dieser Zähler soll über mqtt die Gesamtzahl an iobroker liefern.
    Um einen aktuellen Stand überschreiben zu können, will ich von iobroker kommend einen Wert schreiben können.
    Aber ich bekomme es nicht hin. Im Code unten habe ich die Stellen kommentiert, die Probleme verursachen.
    Ich hoffe ihr steinigt mich nicht, ich bin darin echt schelcht...

    Der aktuelle Code sieht wie folgt aus:

    esphome:
      name: pellet-esp
      platform: esp8266
      board: nodemcuv2
      esp8266_restore_from_flash: True
    preferences:
      flash_write_interval: 5min
    
    # Enable logging
    logger:
    
    ota:
      password: "a9d021e0afcda4e05798857b49ef3b78"
    
    wifi:
      ssid: !secret wifi_ssid
      password: !secret wifi_password
    
      # Enable fallback hotspot (captive portal) in case wifi connection fails
      ap:
        ssid: "Pellet-Esp Fallback Hotspot"
        password: "sv8DdgYL3hZX"
    
    captive_portal:
    
    mqtt:
      broker: 192.168.178.28
      username: mqttuser
      password: !secret api_password
      id: mqtt_client
      birth_message:
        topic: mqtt/0/esphome_sensor/status
        payload: online
      will_message:
        topic: mqtt/0/esphome_sensor/status
        payload: offline
      on_message:
        topic: esphome_sensor/total_pulse_recovery
        qos: 0
        then:
          - lambda: id(total_pulses) = id(total_pulse_recovery); #hier ist ein Problem! total_pulses benötigt int, aber ich bekomme total_pulse_recovery als string
    
    
    status_led:
      pin: GPIO2
    
    globals:
      - id: total_pulses
        type: int
        restore_value: true
        #initial_value: '0'  # hier kann der Zaehlerstand initialisiert werden
    
        
    binary_sensor:
      - platform: gpio
        id: internal_pulse_counter
        pin: D5
        name: "Live-Impuls"
        filters:
          - delayed_on: 100ms
        on_press:
          then:
            - lambda: id(total_pulses) += 1;
    
    
    sensor:
      - platform: template
        name: "Umdrehungen gesamt"
        unit_of_measurement: "U"
        state_class: "total_increasing"
        accuracy_decimals: 0
        lambda: |-
          return id(total_pulses);
        on_value:
          - lambda: id(mqtt_client).publish("mqtt/0/esphome_sensor/mqtt_total_pulses", id(total_pulses));
      
      - platform: mqtt_subscribe
        id: total_pulse_recovery
        topic: esphome_sensor/total_pulse_recovery #/mqtt/0/ wird nicht benötigt: warum?
        accuracy_decimals: 0
    
    
    B 1 Reply Last reply
    0
    • B bastl90

      Hallo zusammen,
      ich habe folgendes vor: ich möchte einen Zähler für Impulse.
      Dieser Zähler soll über mqtt die Gesamtzahl an iobroker liefern.
      Um einen aktuellen Stand überschreiben zu können, will ich von iobroker kommend einen Wert schreiben können.
      Aber ich bekomme es nicht hin. Im Code unten habe ich die Stellen kommentiert, die Probleme verursachen.
      Ich hoffe ihr steinigt mich nicht, ich bin darin echt schelcht...

      Der aktuelle Code sieht wie folgt aus:

      esphome:
        name: pellet-esp
        platform: esp8266
        board: nodemcuv2
        esp8266_restore_from_flash: True
      preferences:
        flash_write_interval: 5min
      
      # Enable logging
      logger:
      
      ota:
        password: "a9d021e0afcda4e05798857b49ef3b78"
      
      wifi:
        ssid: !secret wifi_ssid
        password: !secret wifi_password
      
        # Enable fallback hotspot (captive portal) in case wifi connection fails
        ap:
          ssid: "Pellet-Esp Fallback Hotspot"
          password: "sv8DdgYL3hZX"
      
      captive_portal:
      
      mqtt:
        broker: 192.168.178.28
        username: mqttuser
        password: !secret api_password
        id: mqtt_client
        birth_message:
          topic: mqtt/0/esphome_sensor/status
          payload: online
        will_message:
          topic: mqtt/0/esphome_sensor/status
          payload: offline
        on_message:
          topic: esphome_sensor/total_pulse_recovery
          qos: 0
          then:
            - lambda: id(total_pulses) = id(total_pulse_recovery); #hier ist ein Problem! total_pulses benötigt int, aber ich bekomme total_pulse_recovery als string
      
      
      status_led:
        pin: GPIO2
      
      globals:
        - id: total_pulses
          type: int
          restore_value: true
          #initial_value: '0'  # hier kann der Zaehlerstand initialisiert werden
      
          
      binary_sensor:
        - platform: gpio
          id: internal_pulse_counter
          pin: D5
          name: "Live-Impuls"
          filters:
            - delayed_on: 100ms
          on_press:
            then:
              - lambda: id(total_pulses) += 1;
      
      
      sensor:
        - platform: template
          name: "Umdrehungen gesamt"
          unit_of_measurement: "U"
          state_class: "total_increasing"
          accuracy_decimals: 0
          lambda: |-
            return id(total_pulses);
          on_value:
            - lambda: id(mqtt_client).publish("mqtt/0/esphome_sensor/mqtt_total_pulses", id(total_pulses));
        
        - platform: mqtt_subscribe
          id: total_pulse_recovery
          topic: esphome_sensor/total_pulse_recovery #/mqtt/0/ wird nicht benötigt: warum?
          accuracy_decimals: 0
      
      
      B Offline
      B Offline
      bastl90
      wrote on last edited by
      #2

      @bastl90
      kann geschlossen werden. Ich habe mich an espeasy probiert und hab es damit zum Laufen bekommen.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      Support us

      ioBroker
      Community Adapters
      Donate
      FAQ Cloud / IOT
      HowTo: Node.js-Update
      HowTo: Backup/Restore
      Downloads
      BLOG

      924

      Online

      32.4k

      Users

      81.5k

      Topics

      1.3m

      Posts
      Community
      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
      ioBroker Community 2014-2025
      logo
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Home
      • Recent
      • Tags
      • Unread 0
      • Categories
      • Unreplied
      • Popular
      • GitHub
      • Docu
      • Hilfe