Hi,
I have a sensor for a price of gasoline at the gas station.
sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10
How can I define a trigger when the price changes.
How can I output to Alexa the value of the sonor?
sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10
Normally you would use a numeric state triggger, but if you want it to trigger on any change of state use a state trigger:
trigger:
- platform: state
entity_id: sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10
to:
Having a null to: will trigger on any change of state and ignore attribute changes. If you want to trigger on attribute changes too, then leave out the to: altogether.
For the message:
data:
message: "The price changed from {{ trigger.from_state.state}} to {{ trigger.to_state.state }}"
Or you can just use the sensor state:
data:
message: "The price changed and is now {{ states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10') }}"
thanks for your replay and support. Your code work perfekt.
i would like add the code for check if gas station closed. The problem is, i received a error
This is my code:
{ %if is_states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10', 'unknown') %}
gas station is closed
{% else %}
"The price changed and is now {{ states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10') }}"
data:
message: >
{% if is_states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10', 'unknown') %}
The gas station is closed.
{% else %}
The price changed and is now {{ states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10') }}
{% endif %}
Hi,
This code work perfect. Thanks for this.
I have only one problem for the output to Alexa.
The price for Diesel is 1.969 EUR and the Output to Alexa is 1969 EUR.
What can I do for outcome to 1,969 EUR or 1,97 EUR ?
data:
message: >
{% if is_states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10', 'unknown') %}
The gas station is closed.
{% else %}
The price changed and is now {{ ( states('sensor.tankerkoenig_jet_wuelfrath_wilhelmstr_34_38_e10')|int(0) / 1000 )|round(2) }}
{% endif %}