hi i have a ct sensor that measures the current Amps being used, i would like to multiply this by 230 to get an approximate wattage, does any one know how to do this with a value template?

cheers

hi i have a ct sensor that measures the current Amps being used, i would like to multiply this by 230 to get an approximate wattage, does any one know how to do this with a value template?

cheers

Hello, welcome to the community. What have you tried?

thanks petro

this is what i’ve got

`value_template: "{{ (( states.sensor.measured_current_2 * 230 )) }}"`

no errors but the new sensor has no value

all states are strings. So in order to do any math functions you need to convert the state to a number.

```
value_template: "{{ states.sensor.measured_current_2.state | int * 230 }}"
```

or:

```
value_template: "{{ states.sensor.measured_current_2.state | float * 230 }}"
```

as needed.

but even better would be to use the following syntax:

```
value_template: "{{ states('sensor.measured_current_2') | int * 230 }}"
```

it reduces errors if the entity is unavailable.

perfect! thank you so much

1 Like

Just to be clear the two filters that convert the state text (strings) to numbers do different things. So depending on how much precision you want choose:

`| int`

when you want a whole number with no decimal part (an integer), e.g. 2

`| float`

when you want the decimal part to be included too (a floating point number), e.g. 2.46