Convert binary sensor state into 0 or 1?

Need to do a REST command to send the integer value (1 or 0) of a binary sensor in home assistant. But when I try to do it, I get an error because it sends “on” or “off” rather than 1 or 0.

rest_command:
  water_heater_status:
    url: http://192.168.1.145/rest/vars/set/2/61/{{ states.binary_sensor.water_heater_running.state }}
    username: uname
    password: !secret isy_password

How do I send a numeric value rather than the text value? I tried doing math on it (| float) but that always gives 0 rather than 1 or 0.

{{ is_state('binary_sensor.water_heater_running', 'on') | abs }}
1 Like

{{ 0 if states(‘thing being tested’) == ‘off’ else 1 }}

Bugger, 123 beat me to it

1 Like

@123 and @Mutt, both your suggestions worked! Thanks!!!