Newbie problem
How to use templates in the following situation. Have this UI-generated script:
‘’’
modbustx:
alias: modbustx
sequence:
service: modbus.write_register
data:
address: 5
unit: 1
value: 200
hub: hub1
mode: queued
max: 10
‘’’
Wanted solution is to use a template something like
‘’’
modbustx:
description: “Send set point offset to temperature controller 1”
sequence:>
{% if (is_state(“input_boolean.ibstat1”, “on”) and is_state(“input_boolean.ibstat2”, “off”)) -%}
Code snippets ARE between three back ticks as they should be.
For some reason I was surprised to see what the result looked like. The character I used is ‘’’ before the snippet begins and the same at the end. Seems that ’ character is somehow wrong.
Still fighting with this one. For a pro this must be a piece of cake.
Entity input_number.tupa_korotus is 9.0 at the moment and both booleans are ‘on’.
Have tried just about everything but still no go.
What’s wrong with this script snippet ?
BTW If the code doesn’t show as it should I’m writing this with the last version of Firefox.
I am sure the three Grave Accent characters are OK but still I get the warning of missing backticks.
Is there something I should know about FF when posting ?
alias: modbustx
variables:
valuetosend: >
{% if (is_state('input_boolean.ttupakotona', 'on') and is_state('input_boolean.ttupakorotus','on')) %}
'{{ input_number.tupa_korotus * 10 }}'
{% endif %}
sequence:
- service: modbus.write_register
data_template:
address: 5
unit: 1
hub: hub1
value: '{{ valuetosend | int }}'
mode: single
In addition, if you use the int filter then you should provide it with a default value. For example: int(0) means if the filter is unable to convert the value to an integer, it will report 0.
All 4 will be handled and they should create different values to valuetosend. I only used the first as an example.
Tried the suggested version but it always produces 0. So there must be something wrong with the sequence as well especially value: item.
Glad to hear it resolved the problem. Best wishes to you for the holidays.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.