How do I enter a mathematical formula

Hello everyone,

I have this formula, and I would like to know how I can enter it so that HASSIO can turn on a device for me if the result is equal to a number, for example 10.

Automation should do:
If “Formula” = 10 then turn on light.

The formula I would like to transcribe between the actions would be:

if:
{ (3) * (input_number.xxx | int) * { (10) ^ [ (8) - (input_number.yyy | dec) ] } } = (10 | int)

then:
type: turn_on
device_id: xxxxxxxxxxxxxxxx
entity_id: yyyyyyyyyyyyyyyy
domain: switch

Unfortunately I don’t know how to raise to a power, multiply, add and subtract.
Can you help me do this?

Thanks for your support
Cosiwell

trigger:
  - platform: template
    value_template: "{{ 3 * states('input_number.xxx')|int * 10 ** (8 - states('input_number.yyy')|float) == 10 }}"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.yyyyyyyyyyyyyyyy

Note, the formula result would have to be exactly 10, not 10.00001 to turn the switch on.

1 Like

For future reference:

Jinja2 Math

1 Like

Thank you so much.

If I want the result of the operation it is printed in a text box as if homeassistant works like my scientific calculator?
Is there a “print” command that prints the result in a text-box or similar for use it?

(therefore deleting " == 10")

Use the Template Editor.

Go to Developer Tools > Template