Little Control Box for the Wife – Almost Built

I built it on a Bread Board and got it working for the most part.

For the Hardware I am using a D1 Mini with two Rotary Encoders some 10K resistors and a Touch Sensor for the Fan Power. Software wise I am using ESPHome using the Sensor and Binary Sensor Templates.

### ESPHome Code ###
sensor:
### Right Lamp Dimmer
  - platform: rotary_encoder
    name: "Right Lamp Dimmer"
    pin_a: D6
    pin_b: D7
    min_value: 0
    max_value: 100
    resolution: 2
    filters:
      - delta: 4.0
### Left Lamp Dimmer
  - platform: rotary_encoder
    name: "Left Lamp Dimmer"
    pin_a: D1
    pin_b: D2
    min_value: 0
    max_value: 100
    resolution: 2
    filters:
      - delta: 4.0

binary_sensor:
### Left Lamp Power ON/OFF
  - platform: gpio
    pin:
      number: D5
      inverted: True
    name: "Left Lamp Power"
    device_class: light
### Right Lamp Power ON/OFF
  - platform: gpio
    pin:
      number: D4
      inverted: True
    name: "Right Lamp Power"
    device_class: light
### Fan Power ON/OFF
  - platform: gpio
    pin:
      number: D8
      inverted: True
    name: "Fan Power"
    device_class: cold

To get this to work in Home Assistant I had to create some Automations. Here is one for the Right Lamp Dimmer.

alias: Right Lamp Dimmer
description: ''
trigger:
  - platform: state
    entity_id: sensor.right_lamp_dimmer
condition: []
action:
  - service: light.turn_on
    data:
      brightness: >-
        {{states.light.right_lamp.attributes.brightness | int +
        (trigger.to_state.state| int - trigger.from_state.state | int)*5 }}
    entity_id: light.right_lamp
mode: single

Another Automation for the Power control for the Right Lamp.

alias: Right Lamp Power
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.right_lamp_power
    from: 'off'
    to: 'on'
condition: []
action:
  - service: light.toggle
    entity_id: light.right_lamp
    data: {}
mode: single

It’s the same code for the Left Lamp but the entity_id’s and GPIO Pins are different.

Here is the Schematic.

The 10K Resistors are Pull Up Resistors. It’s also optional to add some 0.1uF snubber Caps on the 3.3V and GND for the Encoders.

Now to find a fancy box to put everything in.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s