Non templetable field - how to do math on parameter

Hi,

I’ve been working a bit on integrating my switchbot curtains with home assistant using ESPHome to act as a relay with the bluetooth devices themselves.

Using PR3398 and PR3434 I’ve got cover entities reflecting the state, current operation and position correctly, and they can be opened / closed just fine.
The slider on the cover entities in the frontend do reflect the position but cannot be used to set it correctly, so I’d like to implement the position_action on my cover template to make that work. The issue is those PRs do not define the fields I need as templetable :

cover:
    [....]
    position_action:
      - ble_client.ble_write:
          id: ${sbcmb_nospace}
          service_uuid: CBA20D00-224D-11E6-9FB8-0002A5D5C51B
          characteristic_uuid: CBA20002-224D-11E6-9FB8-0002A5D5C51B
          value: [0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, HERE]

In the above the value field is not templetable. The doc says pos is passed to the lambda in position_action and contains the position to be set as defined by home assistant, which would be a number between 0 and 1. I need to multiply this by a 100 (since switchbot take percentages for the position) and pass it where the HERE is in the above code. Sadly pos * 100 won’t work in yaml.

Is this impossible without a lambda, or is there some way I could pre-transform the pos variable to an int and pass it in that static field ?
If so, what would it take to make that field templetable, is there a doc somewhere explaining how to make a field templetable ?

Thanks !

If you don’t get a solution here soonish, you could try the ESPHome Discord server where often I get fast and knowledgeable responses for advanced ESPHome queries.

Link as per ESPHome “Join the community”.

I actually asked rbaron and he confirmed he wanted to make those fields templetable, he’s just waiting on the PRs to be merged (hopefully) before working any more on it which is fair.
I’ll just wait on those PRs, it’s not a huge deal, thanks !

1 Like