Script to find out which light is on, translation to numeric value / cover position

Hi

Very beginner, and very not familiar with yaml/phytom/ninja and similar,sorry.

Need help how to “translate” position of “stupid” blinds controled by Philips Dynalite system to numeric value which can than be integrated to position.

I use Dynalite tasks to move blinds, they are stupid up/down without any encoder or position sensor, so i turn on relay and 20sec later i turn it off, by task.
Due limited possibilities and early stage of development of Dynalite MQTT component, only way to communicate is via Dynalite presets which HA understand as lights that can be on and off.

So, i came to an idea:

  • I will use numeric values from 0 (closed blind) to 20 (Fully open) which is also how much seconds it needs to open/close
  • during Dynalite task i can count secnods and when it stops, for example at value 17 (which is almost open) i can call dynalite_blind_livingroom_preset17 and turn it ON.
  • Dynalite-HA component willl transmit that to MQTT and send info that light.dynalite_blind_livingroom_preset17 is on
  • all other, so there are 19 more lights.called preset00 to preset20 are allways off, Dynalite-HA component works that ok.

What i need is script/something that will translate light.dynalite_blind_livingroom_preset17 to numeric value of cover.livingroom position to 17

Of course it wont be that precise, and it is not really extremly usable but i would like to make it work :).
I can make it a bit smarter by reseting value to 0 or 20 when full close/open but that is easy.
What i dont know is “translation” part, finding out which of 21 HA lights is on, and transfering that to cover position.

Thanks for help!

So I don’t know how to get the value into the cover entity, but you could use an input_text (and then maybe eventually get that into a template cover???)

Anyway, if I understand correctly what you’re trying to do, maybe something like this:

input_text:
  cover_pos:

and

automation:
  - trigger:
      platform: state
      entity_id:
        - light.dynalite_blind_livingroom_preset00
        - light.dynalite_blind_livingroom_preset01
        - light.dynalite_blind_livingroom_preset02
        - light.dynalite_blind_livingroom_preset03
        - light.dynalite_blind_livingroom_preset04
        - light.dynalite_blind_livingroom_preset05
        - light.dynalite_blind_livingroom_preset06
        - light.dynalite_blind_livingroom_preset07
        - light.dynalite_blind_livingroom_preset08
        - light.dynalite_blind_livingroom_preset09
        - light.dynalite_blind_livingroom_preset10
        - light.dynalite_blind_livingroom_preset11
        - light.dynalite_blind_livingroom_preset12
        - light.dynalite_blind_livingroom_preset13
        - light.dynalite_blind_livingroom_preset14
        - light.dynalite_blind_livingroom_preset15
        - light.dynalite_blind_livingroom_preset16
        - light.dynalite_blind_livingroom_preset17
        - light.dynalite_blind_livingroom_preset18
        - light.dynalite_blind_livingroom_preset19
        - light.dynalite_blind_livingroom_preset20
      to: 'on'
    action:
      service: input_text.set_value
      data_template:
        entity_id: input_text.cover_pos
        value: "{{ trigger.entity_id[-2:] }}"

This automation will trigger whenever any of the lights gets turned on. It will then set the input_text entity’s state to the last two characters of the entity_id of the light that turned on. Then you can use that as a numeric value with this:

{{ states('input_text.cover_pos')|int ... }}

Hello

Time has come to use your help and idea :slight_smile: only small issue.
I tried to solve it myself, but I’m not that good with scripts and functions and… etc :slight_smile:
Only one thing to make it work, my light.presets are a bit different, unfortunately.

Exact entity is:
light.dynalite_blind_livingroom_preset19_on (for example) and it will go ON if that is the one.
There is also, light.dynalite_blind_livingroom_preset19_off which will turn ON at same moment.

And yes, all other light.dynalite_blind_livingroom_presetXX_off will be ON and
all other light.dynalite_blind_livingroom_presetXX_off will be ON.

Complicated, yes :slight_smile:

But, what is important is how to “rip out” number of light.preset which is on if it name is
light.dynalite_blind_livingroom_presetXX_on so number is at positions 4 and 5 from the back ??

Thanks!

trigger.entity_id[-5:-3]

This is just basic Python. The first number is the index of the first character you want, and the second number is after the last number you want. Negative index numbers mean starting from the end, where -1 is the last character, etc. So [-5:-3] means start with the fifth character from the right end, up to, but not including, the third character from the end.

1 Like

Thank you very much.
It may be basic phyton, but im way to basic noob :slight_smile: