Smart Your Home

4 minutes read | 652 words

Aaruni Kaushik

Some are born great, some achieve greatness, and some have greatness thrust upon them

Last summer, I decided to thrust upon my parents’ house the greatness of being a smart home. I gifted them a tasmota enabled bulb I bought from Athom, and an old laptop to act as a home server. The idea was simple : start with just a single smart device at home, and see if I can expand into the complete experience without my folks complaining too much. As a bonus, we realised the solar inverter installed at home also provides telemetry, which I promptly integrated into the smart home setup.

Home Assistant Dashboard

This time around, it was time to expand on the premise with a few more IoT enabled bulbs, and a 3 button switchboard which all talk on the LAN.

Packaged smart things

The config of bulbs was simple, and is now more or less standard in my setup : 15W RGBWY LEDs pre-flashed with TASMOTA, talking to my MQTT broker, with FADE set to ON, and SPEED set to 10. The bulbs in standby don’t cause a noticable extra load on the solar setup, so I have skipped messing with SLEEP.

The switchboard is a more interesting thing to play with. It comes with 3 buttons, each connected to a relay and an LED, driven by an ESP8266, powered by tasmota. It can then be used in different ways : use the push buttons to work the relays, or use the push buttons as triggers for software defined functions. This way, you can decouple the buttons from the relays, and then control the relays independently from the buttons, or completely ignore that they exist. For now, I have opted to ignore the relays, and use the push buttons to control three of the smart bulbs.

Tasmota Options

The great thing about tasmota is how configurable it is, and how many use cases are supported. For example, instead of using the buttons as simple toggles, you can use them as “clickers”: buttons which behave different based on multi-press or long press.

For this, you must configure tasmota with SetOption73 1 which decouples the buttons from the relays and tunes the firmware for multi press mode. I also configured SetOption32 10 to reduce the waiting time for it to publish a hold action, and SetOption1 1 to not accidentally reset the module while trying to long press.

Now, a single button press publishes over MQTT {"Button1":{"Action":"SINGLE"}}. Other actions are DOUBLE, TRIPLE, QUAD, PENTA, and HOLD. You can now program the software brain of the home (in my case, that’s Home Assistant) to perform actions based on button input.

Home Assistant Automation

For now, I have programmed the switches according to the following ruleset :

  • For action SINGLE, TOGGLE power to the light.
  • For action DOUBLE
    • If brightness is more than half, set the brightness to 49%
    • If brightness is less than half, set the brightness to 100%
  • For action HOLD, reduce the brightness by 10%

I have left triple clicks, quadruple clicks, and pentuple clicks unprogrammed for now, but I am tempted to use those to switch between preset colors for the lights.

Here is the whole automation in yaml :

id: '1652424947680'
alias: Hall-Switch
description: ''
trigger:
  - platform: mqtt
    topic: stat/tasmota_CEEF0F/RESULT
    payload: '{"Button2":{"Action":"SINGLE"}}'
    id: SinglePress
  - platform: mqtt
    topic: stat/tasmota_CEEF0F/RESULT
    payload: '{"Button2":{"Action":"DOUBLE"}}'
    id: DoublePress
  - platform: mqtt
    topic: stat/tasmota_CEEF0F/RESULT
    id: HOLD
    payload: '{"Button2":{"Action":"HOLD"}}'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: SinglePress
        sequence:
          - service: light.toggle
            target:
              device_id: 0e6da970335f2e768593c8d080ef57a3
            data: {}
      - conditions:
          - condition: trigger
            id: DoublePress
        sequence:
          - choose:
              - conditions:
                  - condition: numeric_state
                    entity_id: light.tasmota
                    attribute: brightness
                    above: '126'
                sequence:
                  - service: light.turn_on
                    target:
                      device_id: 0e6da970335f2e768593c8d080ef57a3
                    data:
                      brightness_pct: 49
              - conditions:
                  - condition: numeric_state
                    entity_id: light.tasmota
                    attribute: brightness
                    below: '126'
                sequence:
                  - service: light.turn_on
                    target:
                      device_id: 0e6da970335f2e768593c8d080ef57a3
                    data:
                      brightness_pct: 100
            default: []
    default:
      - device_id: 0e6da970335f2e768593c8d080ef57a3
        domain: light
        entity_id: light.tasmota
        type: brightness_decrease
mode: single