#Bitwise operation in a script..

1 messages · Page 1 of 1 (latest)

potent pollen
#

I'm trying to understand what is my error:
`
set_puffer_setpoint_for_pdc:
fields:
temp:
description: "Temperatura (in gradi) target del puffer"
example: "48"
default: 48
sequence:

  • variables:
    and_result: "{{ states('sensor.temp_target_acqua_del_puffer_raw') | int | bitwise_and(0xFF00) }}"
    final_temp: "{{ and_result | int | bitwise_and(temp) }}"
  • action: notify.mobile_app_sm_a528b
    data:
    title: Test Script
    message: "Final Temp: {{ final_temp }}, temp = {{ temp }}, and_result = {{ and_result }}"
    `
    Final_temp is alway 0, intead temp and and_result have the values that I expect..
    any suggestion to fix it?
warped echo
#

Go to developer tools -> templates and enter the following:
{{ states('sensor.temp_target_acqua_del_puffer_raw') }}

#

Also enter
{{ states('sensor.temp_target_acqua_del_puffer_raw') | int | bitwise_and(0xFF00) }}

#

What do you get?

potent pollen
#

as I wrote, and_result has the expected value and in this case {{ states('sensor.temp_target_acqua_del_puffer_raw') }} is 0x1e2e (7726 dec), {{ states('sensor.temp_target_acqua_del_puffer_raw') | int | bitwise_and(0xFF00) }} is 0x1e00 (7680 dec) ..

#

temp in my case is 46 (0x2e), so if I test the model "{{ (states('sensor.temp_target_acqua_del_puffer_raw') | int | bitwise_and(0xFF00)) | int | bitwise_and(0x2e) }}" the result is 0, but instead it should be 0x1e2e (7726 dec)

#

My bad.. Obviously is 0, the last operation has to be a bitwise_or, not and.. {{ (states('sensor.temp_target_acqua_del_puffer_raw') | int | bitwise_and(0xFF00)) | int | bitwise_or(0x2e) }} = 0x1e2e

#

Sometimes a good night's sleep is enough