Is it possible-ESPhome potentiometer to control different devices?

I’m wondering if it’s possible to hook an ESP home device equipped with a potentiometer to control devices like light dimming, fan speed, thermostats, speaker volume, and other devices that might take variable inputs easier done with a knob.

I’m also wondering if the Phillips hue aurora wireless dimmer switch (I already have this in home assistant) could be used for the same purpose.

It would be great to be able to control multiple devices with a single potentiometer or Aurora, but I’d be fine with having a dedicated knob per device if that’s the best that could happen.

Yes. Sure this is possible. Where exactly is your problem?
Attach the poti to the ADC input (make sure to obey the ADC voltage range of your MCU). Use an Analog To Digital Sensor to transfer the ADC value to HA. In HA create an automation to control whatever you want with the ADC value.

1 Like

Thanks, I’m a noob and have had HA for a matter of weeks. I understand most of what you said. I’m not sure how to expose the potentiometer values to HA yet. You said to use an analog to digital sensor. Can you explain that a bit further?

Did you see this?

And you can combine the ADC sensor with the linear calibration option.

2 Likes

Other idea, use a rotary encoder (same same but different).

They can turn “unlimited” and most of them have even a “push button” integrated on the shaft.

The esphome integration makes it also much easier to work with compares to the adc component:

2 Likes

This sounds like you have never exposed any ESPHome sensor to HA? The process is really simple!
I recommend that you check some Youtube videos about that. There are plenty available.

In a nutshell: You add some sensor in your ESPHome YAML (i.e. the fore-mentioned Analog To Digital Sensor) together with the WiFi Component and the API Component and that’s it. Just compile and upload the code to the MCU.
When HA sees your MCU for the very first time you may have to accept the newly found ESPHome device in HA’s frontend in the section Configuration → Integrations. But you only need to do this once.

Thanks so far. Struggling with the automation part now.

I have a the esp equipped with a rotary encoder and see the change in my dashboard however I’m not sure how to pass the value to a light to dim or brighten it when the encoder changes value. Under the “Actions”, is there something I’m missing. I feel like I should see a way to pass in my rotary encoder value.

Not an automation expert (as I do all this in Node Red) but this should work:
Set action to “Call service”, service to “Light: turn on”, add your target entity, switch to YAML mode (three dot menu) and add a data_template: block that sets the brightness: data parameter with a template that references the state of your rotary switch entity.

Should be something like:

action:
  service: light.turn_on
  entity_id: light.office_light
  data_template:
    brightness: >
      {{ states('sensor.rotary_encoder_3')|int }}

Also see this posting:

A little futher, still on the automation.

So this automation seems to trigger only when I pass the “0” and “100” thresholds. It doesn’t trigger continuosly. Seems like I should find a value change trigger?

What I have so far:

description: ''
trigger:
  - type: value
    platform: device
    device_id: 5685ed64cdeb6b9181c03e4a330101b4
    entity_id: sensor.rotary_encoder_3
    domain: sensor
    id: sensor.rotary_encoder_3
    above: 0
    below: 100
condition: []
action:
  - service: notify.notify
    data:
      message: value changed
  - data_template:
      brightness: '{{states(''sensor.rotary_encoder_3'')|int }}'
    entity_id: light.round
    service: light.turn_on
mode: parallel
max: 10

Not even a thank you. Just the next request for help.
Very rude.

Ah sorry, I am actual very grateful for the help so far. I am learning from the forum and respect your time and contribution here.

Got this going with @Jpsy and @tom_l 's help. Thanks, working well with a WemosEsp $3 and a rotary encoder $2. Need to come up with an enclosure…

YAML:

alias: Small Volume Knob
description: ''
trigger:
  - platform: state
    entity_id: sensor.rotary_encoder5
    id: sensor.rotary_encoder5
condition: []
action:
  - service: media_player.volume_set
    target:
      device_id: 5a3838ba2c012cf630bbddda0b307ee8
    data:
      volume_level: '{{ ( states(''sensor.rotary_encoder5'')|float(0) * 0.01 )|round(2) }}'
mode: parallel
max: 10

ESPHome YAML:

esphome:
  name: small-esp
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "ef4dbb1586c342eaf9512a110bf94e42"

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

  manual_ip:
    static_ip: 192.168.3.153
    gateway: 192.168.3.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Small-Esp Fallback Hotspot"
    password: "SqioPkLZTB80"

captive_portal:
      
sensor:
  - platform: rotary_encoder
    name: "Rotary_Encoder5"
    pin_a: GPIO5
    pin_b: GPIO4
    
switch:
  - platform: gpio
    pin: GPIO2
    name: "High"
    restore_mode: RESTORE_DEFAULT_ON


image

4 Likes

Very nice compact :pinching_hand: build :+1:
Are you powering the encoder (+) from pin D4 on your d1 mini? :thinking:

yes.

have to type at least 10 characters to post.

nice :wink:

Can someone help me understand how the pot is powered from D4? I thought that the pins were wither high or low, not able to provide power to anything? Thank you and appreciate the insight!

Oh, I see it called out as GPIO2 and set to High… So the D1 mini is powering the encoder via D4 (GPIO2), it looks as also the encoder has a button function that you are not using, but hooked to D3 (GPIO0), correct?

I’m new to this, but guessing that you either do not use the switch (GPIO2) on the front end in Home Assistant, or that it is not displayed?

I’m looking at this for a fan speed control, and using the button function to toggle the fan on and off.

Thanks!

I have no idea why the rotary encoder is powered through GPIO02 in the diagram of the OP. You should instead connect it directly to 3.3V. No need to waste a GPIO for that. You better use it for the integrated push button function of the rotary encoder.

In the photo, it looks like the switch output it connected to D3 (GPIO 0). I suppose the OP did it this way to not have to run a separate wire for the 3.3v that the rotary encoder needs. It looks like the Wemos can supply 3.3v on GPIO pins. I had never thought of it being able to run a periphery like that though.
The way he has it wired and connected makes for a very nice little package that only needs 5v to operate and can be connected directly to a usb plug. For volume control as he is using it, it makes great sense I think!

1 Like

@NateVolk’s got it! You’re on the money. The encoder is powered with GPIO pin 2 because I like the smaller package without wires, I don’t care about wasting the other GPIO pins I only wanted volume. I have the push button working the goal was to cycle through devices that could use a variable input from the potentiometer like thermostat, dimming lights, different volumes, blinds, fans, etc but I haven’t done that part yet. Video.

I have a large family; the family room entertainment center is a mess with an xbox, playstation, directv, appletv, and google cast. All audio is routed to a Google Home Max because we lose remotes, you can control all said devices with voice commands using a Harmony Hub paired with Google. It’s frustrating at times and with kids the volume gets out of hand so all I wanted was a simple volume knob to control the Google Home Max volume at any point.

I tried to build the volume knob with a battery and wireless charger but never did get the Wemos low power stuff working and the battery died within hours. Anyways I just made a wood enclosure and wired it with a usb cable. I’m happy with it.



2 Likes