natekspencer / hacs-pura

Home Assistant integration for Pura smart fragrance diffusers
MIT License
18 stars 1 forks source link

Automation Best Practices #21

Closed lux4rd0 closed 12 months ago

lux4rd0 commented 1 year ago

The request

Looking to obtain better automation details for controlling the Puras. A few things I've noticed:

Turning off using the device "Pura Switch" doesn't seem to work. I need to change the "Select Fragrance" to "Off"

alias: Loft Pura Off
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.tyle_2nd_floor_group_motion
    to: "off"
    for:
      hours: 0
      minutes: 20
      seconds: 0
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      device_id:
        - f8330d0b811b3346772835b955e3376d
    enabled: true
  - service: select.select_option
    data:
      option: "Off"
    target:
      device_id:
        - f8330d0b811b3346772835b955e3376d
mode: single

Same thing for turning on. But I must also choose the "Number Set" for the Intensity.

alias: Kitchen Pura On
description: ""
trigger:
  - type: motion
    platform: device
    device_id: e282806df8715c1589fbc8075bcf873f
    entity_id: 64af6c043184a1e3d6ddb23cf3b7c2b6
    domain: binary_sensor
condition:
  - condition: state
    entity_id: input_select.mode
    state: Home
action:
  - service: light.turn_on
    data:
      color_name: aqua
      brightness_pct: 100
    target:
      device_id:
        - f5768d206b8fbca08efba0736c39fab8
  - service: select.select_option
    data:
      option: "Slot 2: Volcano"
    target:
      device_id:
        - f5768d206b8fbca08efba0736c39fab8
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: number.set_value
    data:
      value: "4"
    target:
      entity_id:
        - number.kitchen_pura_diffuser_intensity
mode: single

Doing so requires a manual field entry for the Scent and the slot. For this example, "Slot 2: Volcano". There's no way to simply "turn it on" regardless of scent. If I change the scent - I need to update the automation.

For some reason - the "switch.turn_on" service with the Pura device doesn't actually have a "switch" entirety. (Just for Ambient mode and Away mode"

I also need to add a delay when turning on the switches because there's no scent selected when it's turned off (by selecting no scent"), And the automation will fail. Sometimes, it takes longer than 5 seconds (in my example).

Can a new service be added to your integration to handle these items? Or a recommended blueprint?

New Puras

Must reload the Device Integration for new Puras to show up.

Screenshots

No response

Which Pura device(s) is this request for?

Additional information

No response

natekspencer commented 1 year ago

Turning off using the device "Pura Switch" doesn't seem to work. I need to change the "Select Fragrance" to "Off" ... For some reason - the "switch.turn_on" service with the Pura device doesn't actually have a "switch" entirety. (Just for Ambient mode and Away mode"

There is no "Pura Switch" entity to control the fragrances as the primary way to control this device is by utilizing the select entity.

Same thing for turning on. But I must also choose the "Number Set" for the Intensity.

This functionality is similar to the app in that a fragrance must be on before adjusting intensity. However, both this integration and the app will turn the fragrance on to the previous intensity setting. There is no need to set the intensity after selecting a fragrance unless you wish to adjust it.

Can a new service be added to your integration to handle these items? Or a recommended blueprint?

There is a service to start a timer pura.start_timer which actually allows for all of the things you've talked about. You can select the device, optionally select the slot regardless of fragrance (or leave blank and it will choose the bay with the most fragrance remaining), set an intensity and a duration for it to run.

Some of the issues you have brought up are related to the entity model available in Home Assistant, how it natively displays things and the ease of use controls it provides while the other is based on choices I made to bridge that gap based on my interaction with both the Pura app and Home Assistant and trying to simplify how it shows up in Home Assistant. For instance, in the Pura app, to start a fragrance you have to navigate to the desired fragrance and then click "Start". But because of that, you know which fragrance you are in and a few other things. In Home Assistant, that could have been done by adding "sub devices" for each bay/slot which have their own switch, intensity, etc. It gets a little convoluted though. And because they can't both be on at the same time, it can cause more confusion and nuances with the interaction within Home Assistant and building automations.

Must reload the Device Integration for new Puras to show up.

I need to look and see if Home Assistant has made it easier to add new devices that show up. But it's definitely much simpler to reload the integration than to code and test the whole process, haha.

lux4rd0 commented 12 months ago

Thanks for the details here. Ultimately, I want to use my motion sensors to turn on and off my Puras in each room when occupancy changes (with duration delays). The "Away Mode" doesn't suit this need as it uses your phone to determine proximity, and that's not useful for individual rooms or multiple people in the house.

Your timer service is nice because it allows you to choose a slot without defining a fragrance, which may work. I don't need the timer, but I could simply set that to a high number and still turn it off by deselecting the fragrance. But your timer may still turn off at the end of the duration, even if I want to keep it on because of recent motion. Or if I set it for 20 minutes, the motion will reset the duration.

I'll try this out and see if it accomplishes the same outcome that I'm looking for. I think it may! Thanks!

natekspencer commented 12 months ago

Thanks for the details here. Ultimately, I want to use my motion sensors to turn on and off my Puras in each room when occupancy changes (with duration delays). The "Away Mode" doesn't suit this need as it uses your phone to determine proximity, and that's not useful for individual rooms or multiple people in the house.

This is exactly what I do with my Pura devices. Away mode and schedules just isn't intuitive enough for my use case. Another reason I actually like the timer is that it should allow for the device to turn off automatically in case there is an issue with the API (I haven't actually tested this). Also, if you start another timer, it will replace the existing timer on the device so you can keep "extending" it.

lux4rd0 commented 12 months ago

Thanks! I moved everything over to the service, and it looks like it's doing what I want. The timer function on the Pura side helps now that I see it getting reset with every detected motion. It does replace the existing timer on the device.

All good!! Thanks!