Persistent setting / number - how?

I’d like to be able to set a variable / number on the web_server webpage, have it persist during reboots, and use that number in some calculations.

I’ve tried to do my homework, and the closest I could find was probably this guide: ESPHome variables from Home Assistant - Schinckel.net
Difference being, I’d like it to be set in either the web page, or alternatively over MQTT.

Use Case:
I have a pellet furnace where I found a UART port that dumps the current parameters once a second (including output %).
I’d like to multiply this output number with the furnaces current max output setting (set by the user on the furnace, but not dumped over UART), and the pellets calorific value to get a kWh reading that I can use in the Gas Consumption tab of of the Energy dashboard.

I’ve tried different approaches, none work and I feel like I’m missing a simple solution.

Latest approach was to simplify and do this, but this does not give me an option to setting it in the web interface:

number:
  - platform: template
    name: "Max Output"
    min_value: 1.0
    max_value: 6.0
    step: 0.05
    icon: 'mdi:cog'
    restore_value: true
    initial_value: 1.0

Thanks - Martin

Hi @nickrout

It seems to me that what you are linking to is a Home Assistant thing, and not a ESPHome thing?

Lord, how many times have I missed the ESPhome tag, sorry 'bout that.

1 Like

What platform are you working on?

ESP8266 requires an explicit restore_from_flash config.

ESP32 I assume just does it, the only issue you could run into when testing is the flash_write_interval, flash is only written every 60 seconds by default I think, to save flash wear.

I should read better too - your main issue is not being able to set from the web interface? Sorry I am not much help there…

But if you have a web browser open, why not set the value in the normal HA interface and use a home assistant sensor in esphome to bring the value in.

Ok - this sample does just that, it exposes the number on the web page (the ESPhome web interface, not HA - right?) and lets you set it.

It also persists over restarts and does a pretty basic calculation with the value as well (just adds 0.05 to it on reboot).

esphome:
  name: webinterface
  on_boot:
    priority: 600
    then:
      - number.set:
          id: max_output
          value: !lambda "return id(max_output).state+0.05;"

esp32:
  board: esp32dev
  framework:
    type: arduino
      
# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "c1c4c455c995776545f45707eaecc11d"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Webinterface Fallback Hotspot"
    password: "s0KgLdaE9uc7"

captive_portal:
    
web_server:
  port: 80
  
number:
  - platform: template
    name: "Max Output"
    id: max_output
    min_value: 1.0
    max_value: 6.0
    step: 0.05
    icon: 'mdi:cog'
    restore_value: true
    initial_value: 1.0
    optimistic: true

Also - if you mean the HA web interface the this also will expose it there - as a slider that you can set…

No worries with the reading guys. I was a little surprised when I came here to se how much ESPHome is married to Home Assistant.

I just happen to have recently migrated some of my things to Home Assistant. But I’d like to be able to go back to OpenHAB some day if I feel like it.

HA is not on the same VLAN as my ESP devices, so I’d like to keep the the communication going through MQTT if possible.

Its running on a ESP8266 for what its worth.

And thanks for the code snipped @zoogara . I’ll try it out in a day or two when I have time!

Its funny. I write C++ in my day job, but much of the YAML syntax with ESPHome just seem…
I can read and understand it, but I can’t read the documentaion without examples and figure out that in on_boot I can put a then: and a nested number.set ect.