ESPHome + Hubitat

I took a quick look at the repo for Konnected and it should be supportable using the ESPHome library I built by writing a customized driver that exposes each of the zones as a child device (e.g. contact sensor, smoke etc.) and with child button/switch devices to activate any konnected outputs.

You should have no problem connecting to it from HA and Hubitat, ESPHome can support multiple connections to its API.

My suggestion would be to use something like Node-Red and then you can push that out to Hubitat. While the ESPHome library would be able to access the data directly, it is likely to overload the small processor on the Hubitat with that much data streaming in.

Thank you @jonathanb for the great work on this. The one thing I can not figure out is the correct way to create the devices in Hubitat when there is more than one entity that needs control. My use case is a TUYA chip replacement of a RGBCCW light that has one entity for the CCW light and another entity for the RGB light. The CCW Light is the main light and the RGB is a ring t hat lights up the ceiling as ambient light. I have it working in other platforms, but can not figure out the right way to do it in habitat. Since it has the same IP address, I can not create more than one device and choose the entity on each. I also tried my own driver just for RGB and just for CCW, but again, it is the same device, so it can not detect the second one, and the first one gets messed up as well.

Thanks,

You will want to create child component devices from your main driver, in this case, two child components, a Generic Component RGBW and a Generic Component RGB.

You will then send events to those child component devices (using the parse method on them) and receive commands via the 'component' prefix methods that will be called from the child device back to the parent when a command is selected.

Here is an example for a dynamic number of child switches.

Notice that it creates children:

ChildDeviceWrapper dw = getChildDevice(dni) ?:
                    addChildDevice(
                        'hubitat',
                        'Generic Component Switch',
                        dni
                    )

Then when it wants to update the switch it calls parse:

getChildDevice(dni)?.parse([
                    [ name: 'switch', value: value, type: type, descriptionText: "switch is ${value}" ]
                ])

Lastly, it needs a way to know when those child switches are turned on and off, these two methods in the parent take care of that:

public void componentOn(DeviceWrapper dw) {
    String key = dw.getDeviceNetworkId().minus("${device.id}-")
    if (dw.currentValue('switch') != 'on') {
        if (logTextEnable) { log.info "${device} on" }
        espHomeSwitchCommand(key: key as Long, state: true)
    }
}

public void componentOff(DeviceWrapper dw) {
    String key = dw.getDeviceNetworkId().minus("${device.id}-")
    if (dw.currentValue('switch') != 'off') {
        if (logTextEnable) { log.info "${device} off" }
        espHomeSwitchCommand(key: key as Long, state: false)
    }
}
1 Like

Thank you. I will work on that tonight.

Does anyone know how create this function in Esphome?

I want to turn on switch-B if another switch-A has been and stays on for 3sec and the reverse if switch-A has been off and stays off for 3sec then switch-B is set to off.

I have tried script with reset control and 'for condition' with time set. But I cant seem to mimic the action of a latching flip/flop.

I have a sensor that detects distance and when it reaches a target range, it turns on a switch, if it's out of range, then off. I only want the control switch to turn on if the 'ranging' switch has been in a stable state for 3sec or more. I don't want to debounce or throttle filters on the sensor, because the moving action is too fast and it might be missed.

Have you tried asking on their Discord? ESPHome

No, im not signed up for that yet.

Can I get a driver for Temp Sensor? I'm not smart enough to write one.

Sure, I'll add an example temp sensor driver as soon as I get a chance :slight_smile:

I don't have a temperature sensor to hand for testing so it might need tweaking but here is a temperature and humidity driver example:

https://raw.githubusercontent.com/bradsjm/hubitat-public/development/ESPHome/ESPHome-TemperatureSensor.groovy

Thanks for your work!

Is it possible to get a code that combines multi contact sensor and multi switch in one code?

@jonathanb I tried to add an illuminance sensor to your posted example. It seemed simple enough to copy/paste/replace one of components with 'illuminance' and add in with same syntax. I looked up the driver definition for Hubitat and added that capability, following example.

IlluminanceMeasurement

Device Selector

capability.illuminanceMeasurement

Driver Definition

capability "IlluminanceMeasurement"

** Here is the resulting driver code additions (illuminance):



input name: 'Illuminance', // allows the user to select which sensor entity to use
   type: 'enum',
   title: 'ESPHome Illuminance Entity',
   required: state.sensors?.size() > 0,
   options: state.sensors?.collectEntries { k, v -> [ k, v.name ] }
...
...
...
case 'illuminance':
   // This will populate the cover dropdown with all the entities
   // discovered and the entity key which is required when sending commands
   state.sensors = (state.sensors ?: [:]) + [ (message.key): message ]
   if (!settings.illuminance) {
   device.updateSetting('illuminance', message.key)
   }
   break
...
...
...
    if (settings.illuminance as Long == message.key && message.hasState) {
       String value = message.state
       if (device.currentValue('illuminance') != value) {
          sendEvent([
             name: 'illuminance',
             value: value,
             unit: 'lux',
             descriptionText: "Illuminance is ${value}"
           ])
       }
       return
    }

Here is the relevant esphome yaml configuration:

sensor:
  - platform: adc
    pin: A0
    name: "Illuminance"
    id: illumminance
    update_interval: 5s
    unit_of_measurement: lux
    accuracy_decimals: 0
    filters:
      - lambda: |-
          return (x / 10000.0) * 2000000.0;

  - platform: dht
    pin: D4
    temperature:
      name: "Temperature"
      unit_of_measurement: "°F"
      filters:
        - offset: -4
        - lambda: return x * (9.0/5.0) + 32.0;

    humidity:
      name: "Humidity"
    update_interval: 60s

And the log shows:

dev:28352023-03-25 02:21:19.048 PM debug ESPHome received: [type:state, platform:sensor, key:1797020032, state:129.296875, hasState:true]

But the device Current State never gets populated and the pull down entry does not include an option for Illuminance:

Because the platform is "ADC", ESPHome doesn't provide a default device class unlike for temperature (which has an explicit temperature platform)

Fix should just be to explicitly define the device class by adding:

- platform: adc
    pin: A0
    name: "Illuminance"
    id: illumminance
    device_class: "illumminance"
1 Like

This should combine them:

https://raw.githubusercontent.com/bradsjm/hubitat-public/development/ESPHome/ESPHome-MultiSwitchSensor.groovy

1 Like

That's much better than the work-around I came up with. I added voltage measurement as a capability and reworked the state case as

if (state.voltage as Long == message.key && message.hasState) { Integer voltage = round(message.state as Float)

This worked much better! Thank you...

wow! Thanks for the code and the speed, really apreciated! it works perfectly!

Any chance there would be any way to incorporate the UpsyDesky with your ESPHome integration? The yaml files tjhorner put together to incorporate the UpsyDesky into HA are available on his github... This would be my first time incorporating something with ESPHome into HE, so just curious if anyone has any thoughts before I order one from him to automate my new Uplift desk. :nerd_face:

I took a quick look at the YAML and I don't see any reason why it would not integrate with a customized driver using my ESPHome library :slight_smile:

1 Like