Run function for sensor data --> singed decimal to bin

Hey i have a sensor which is working and represent 16 bin array as singed decimal number .
bit 16 gives negative prefix

i would like to filter each bit in order to get he input states,
What would be the best solution for it ?
Can i run python script to insulate particular bit status?

The latest HA release added bitwise filters to its templating extensions which you could use. See the end of the list. And, yes, Python also has bitwise operators you could use to extract bits. Which route is easier probably ultimately depends on what you want to do with the data and your coding background.

I want to get information bitwise for 16 bit number

i assume i will have to do bitwise_and(value_one, value_two)

value_one will be the sensor data, value two the number i would like to compare ( represent bit value i am seeking for?)

how to use the syntax in template?

this what i have tried… i get string in the sensor data… not the results of the and function…

  • platform: template
    scan_interval: 1

    friendly_name: "IN_A"
    value_template: >
      bitwise_and({{ states('sensor.dio')}}, 1)

What does the state of sensor.dio look like?

just a simple number represent as string

I haven’t updated HA so I can’t try this myself, but I would think this should work:

value_template: "{{ states('sensor.dio')|int|bitwise_and(1) }}"