button-card icon indicating copy to clipboard operation
button-card copied to clipboard

Haptics support

Open SeanPM5 opened this issue 6 years ago • 25 comments

Robbie has added haptics support to the official Home Assistant iOS app (update releasing in a day or two). The PR for it is here (requires 0.92 also releasing in a day from now): https://github.com/home-assistant/home-assistant-polymer/pull/3099

Haptics basically vibrates the part of the screen that you touch (in a subtle way), so you get physical feedback on button presses like in real life. It's very nice.

As per balloob's comment at the bottom of that PR, it appears that custom cards can also use this new feature:

The nice way about this approach of using events is that custom stuff can also implement it 👍

It seems that you just have to fire a certain event when button is pressed and the iOS app will listen for that event and then handle the vibration/haptics part. Robbie is active on Discord #ios channel and could help out with any implementation questions I'm sure.

It would be a truly killer feature to have this supported in button-card as well. And I think would even be much better than the official entity-button implementation because we'd be able to specify exact sensitivity level on per-button basis, for example haptics: light (possible options seem to include: success, warning, failure, light, medium, heavy, selection)

Hopefully this can be considered. I would be happy to help test things.

SeanPM5 avatar Apr 23 '19 19:04 SeanPM5

It's just a firing of an event, so easy enough...the # of options in this card are starting to melt my brain...

iantrich avatar Apr 23 '19 20:04 iantrich

Nice, I'll look into that once I'm finished with the typescript conversion, seems quite easy :+1:

Also yeah so much options...

RomRider avatar Apr 23 '19 21:04 RomRider

@SeanPM5, could you please try this file and let me know the result as I don't own an IOS device? https://raw.githubusercontent.com/custom-cards/button-card/haptic/dist/button-card.js

Usage:

tap_action/hold_action:
  action: usual stuff
  [...]
  haptic: success | warning | failure | light | medium | heavy | selection

(Will change to haptics instead of haptic later... typo in the code :) )

RomRider avatar Apr 24 '19 15:04 RomRider

Have to wait until next beta build of the Home Assistant iOS app becomes available before I can test it (scheduled for ~Thursday/tomorrow I think~ 0.92.1), but that will definitely be the very first thing I try and I'll report back.

Thanks for adding this!

SeanPM5 avatar Apr 24 '19 17:04 SeanPM5

@SeanPM5 is getting me a few test cases and I'll try them out and let you know if it works @RomRider. Thanks for implementing, you are the first! I plan to add support for Android in the official app that I am beginning work on soon, although my basic research tells me that Android generally doesn't have a nice "taptic engine" like iPhone does so not sure if I'll be able to accurately replicate the patterns as defined by the iOS HIG.

robbiet480 avatar Apr 24 '19 23:04 robbiet480

As I said on the PR, all is working fine.

robbiet480 avatar Apr 25 '19 00:04 robbiet480

I didn't plan to release it like this it is in the PR but we can as a sort of MVP.

I don't know the feeling of it, as currently it's going to vibrate when you release the screen with your finger. Maybe what we can imagine is to have:

  • on screen press, tap_action.haptic (or light if undefined and on_hold is different from none)
  • when it switches to on_hold use the haptic from it, if any
  • on release, I'm not sure what to do?

Thoughts @SeanPM5 @robbiet480?

RomRider avatar Apr 25 '19 05:04 RomRider

Also @robbiet480, when this feature is released on this button, where should the users download the "beta" ios app with haptic support included?

RomRider avatar Apr 25 '19 05:04 RomRider

@RomRider http://home-assistant.io/ios/beta

robbiet480 avatar Apr 25 '19 07:04 robbiet480

Merged and released. I'll keep this open to gather feedback.

RomRider avatar Apr 25 '19 08:04 RomRider

Almost forgot, here was the test config I did, contains all seven different haptic levels and was confirmed working by Robbie. So when the next iOS beta app releases this should be a good and fast way to try it out.

  #### IOS HAPTIC TEST CONFIG - https://github.com/custom-cards/button-card/issues/121
  - type: horizontal-stack
    cards:
      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        color: green
        icon: mdi:check-circle
        name: Success Haptic
        show_state: false
        tap_action:
          action: more-info
          haptic: success

      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        color: "#f9c536"
        icon: mdi:alert
        name: Warning Haptic
        show_state: false
        tap_action:
          action: more-info
          haptic: warning

      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        color: "#ff0000"
        icon: mdi:message-alert
        name: Failure Haptic
        show_state: false
        tap_action:
          action: more-info
          haptic: failure

  - type: horizontal-stack
    cards:

      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        icon: mdi:feather
        name: Light
        show_state: false
        tap_action:
          action: more-info
          haptic: light

      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        icon: mdi:medium
        name: Medium
        show_state: false
        tap_action:
          action: more-info
          haptic: medium

      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        icon: mdi:pig
        name: Heavy
        show_state: false
        tap_action:
          action: more-info
          haptic: heavy

      - type: "custom:button-card"
        entity: sun.sun
        color_type: card
        icon: mdi:selection-off
        name: Selection
        show_state: false
        tap_action:
          action: more-info
          haptic: selection

Thanks again guys!

SeanPM5 avatar Apr 25 '19 08:04 SeanPM5

The iOS beta was released a few hours ago, I have been testing haptics on the button-card it and it works very well. The subtle physical feedback makes quite the difference in my opinion. Awesome stuff, I plan to update every single one of my buttons to use it.

The problem I've sorta noticed very quickly though with the current implementation, is that syntax is nested under tap_action and hold_action. So if your custom:button-card doesn't have either of those things, there's no way to add haptic (easily at least). For example I have many cards like this:

- type: custom:button-card
  entity: switch.vizio_tv
  icon: mdi:television
  name: TV
  color_type: card
  color: "#7CBE6E"

and this:

#### PODCASTS TOGGLE
- type: custom:button-card
  icon: mdi:podcast
  name: Podcasts
  color_type: card
  state:
  - value: 'on'
    color: "#f9c536"
  entity: input_boolean.display_podcasts
  service:
    domain: input_boolean
    action: toggle
    data:
      entity_id: input_boolean.display_podcasts

among others that do not have tap_action or hold_action specified, that I want to add haptics to...

I kind of think haptic should be top level option too, so in the above example you could just add the one line:

- type: custom:button-card
  entity: switch.vizio_tv
  icon: mdi:television
  name: TV
  color_type: card
  color: "#7CBE6E"
  haptic: light

SeanPM5 avatar Apr 29 '19 08:04 SeanPM5

@SeanPM5, if I understand correctly, because you don't want to have to define the toggle action each time (as it's the default action), you'd like to have a main config entry for haptic. Is that correct?

On a side note, this config is not valid:

#### PODCASTS TOGGLE
- type: custom:button-card
  icon: mdi:podcast
  name: Podcasts
  color_type: card
  state:
  - value: 'on'
    color: "#f9c536"
  entity: input_boolean.display_podcasts
  service:        # <----- This doesn't exist anymore, but it works because toggle is default :)
    domain: input_boolean
    action: toggle
    data:
      entity_id: input_boolean.display_podcasts

RomRider avatar Apr 29 '19 09:04 RomRider

Or should haptic be default?

iantrich avatar Apr 29 '19 13:04 iantrich

Correct @RomRider . I wish to add haptic to all of my buttons, and I suspect that most people would want to do the same. If it was a main config entry it'd be a lot easier to update them all without needing to add tap_action and such on buttons that don't necessarily need it.

But I think @iantrich idea would work well, if haptic was default for all buttons then people wouldn't need to update anything at all in most cases (unless they wished to override the default sensitivity for a certain button by adding haptic: heavy for example).

The other benefit of making it default, is that is how the iOS app does it with the core entity-buttons etc so the behavior would be familiar and consistent, especially for those who have a mixture of default entity-button and custom-button inside of the same view.

SeanPM5 avatar Apr 29 '19 16:04 SeanPM5

@SeanPM5, what would be the best option for the default value? Is that light? If we have a default value, I'll also add an option to disable haptics (haptic: none)

RomRider avatar May 01 '19 11:05 RomRider

Sorry for the late response, I had been meaning to test and got busy the last few days and lost track.

I think that light would be a good default value, and haptic: none is a great idea as well.

There's also a toggle inside of iOS itself (under Sounds & Haptics section) that users can disable haptics across the entire operating system - and the Home Assistant iOS app respects that OS-level setting too. So users that don't like haptics at all will likely have disabled it from that OS setting already.

You can get an idea of what it's like in the middle of this page where it says "Haptic Feedback." On the right side of that page you can test the haptic levels which plays a sound and animation. It's not the same as actually feeling it on the device, but it should give you a more better idea. After playing with that page, I think you will agree that light is probably the best default.

SeanPM5 avatar May 07 '19 19:05 SeanPM5

Just revisiting this now that support was added to core. Starting in Home Assistant 0.99 it's now sending light haptic by default on the core entity button. PR here: https://github.com/home-assistant/home-assistant-polymer/pull/3569

So I think that it would be a smart idea to match the behavior of core button with this card and send light by default.

SeanPM5 avatar Sep 17 '19 20:09 SeanPM5

https://github.com/custom-cards/custom-card-helpers/pull/6/files

iantrich avatar Sep 17 '19 20:09 iantrich

We will want to add a none option for haptic then.

iantrich avatar Sep 17 '19 20:09 iantrich

This will require a modification in custom-card-helper

RomRider avatar Sep 17 '19 20:09 RomRider

For none? I don't think so. If passed to forwardHaptic is will just not produce anything. The other option is to have button-card set light as the default

iantrich avatar Sep 17 '19 20:09 iantrich

Any chance to adapt this code to work on the android APP?

tenkaibr avatar Jul 25 '20 12:07 tenkaibr

Normal Buttons also emit an Vibration Event in the Android App. Could this be also implemented into custom:button-card? Or is this an Android Companion thing?

fti7 avatar Sep 11 '20 08:09 fti7

@iantrich any chance of this getting through for Android too?

clau-bucur avatar Jul 10 '24 16:07 clau-bucur

Android Companion App now supports haptic.

Created #956 to add default haptic at configuration level.

dcapslock avatar Aug 25 '25 00:08 dcapslock