poudenes
(Poudenes)
January 11, 2021, 10:32am
1
Hi All,
Try to use the attribute
part in trigger. But then it won’t work. Or is this only work with a numeric_state
?
Without:
from: 'false'
to: 'true'
attribute: stock_available
Everything work, but its not the best way.
All sensors have a attribute stock_available
with value True
or False
(with a capital T or F)
When I change the value in developer tool nothing send out as notification.
Here the whole script:
- alias: "ToGoodToGo - All shops"
trigger:
- platform: state
entity_id:
- sensor.toogoodtogo_broodhuys_meijer_magic_box
- sensor.toogoodtogo_albert_heijn_amsterdamseweg_amstelveen_magic_box
- sensor.toogoodtogo_albert_heijn_to_go_amsterdam_wtc_magic_box
- sensor.toogoodtogo_boulangerie_noe_gustav_mahlerlaan_amsterdam
- sensor.toogoodtogo_de_drie_graefjes_stadionplein_amsterdam
- sensor.toogoodtogo_hema_gelderlandplein
- sensor.toogoodtogo_lidl_amsterdamseweg_188_groente_fruit_box
- sensor.toogoodtogo_lidl_bankrashof_groente_fruit_box
- sensor.toogoodtogo_starbucks_gustav_mahler_amsterdam
- sensor.toogoodtogo_sushi_time_wtc_amsterdam_magic_box
- sensor.toogoodtogo_the_roastary_magic_box
- sensor.toogoodtogo_poke_perfect_zuidas_magic_box
- sensor.toogoodtogo_juicebrothers_gustav_mahlerlaan_magic_box
- sensor.toogoodtogo_le_pain_quotidien_gelderlandplein_magic_box
- sensor.toogoodtogo_stadsbakker_jongejans_gelderlandplein_magic_box
from: 'false'
to: 'true'
attribute: stock_available
variables:
stock: "{{ states(trigger.to_state.entity_id) }}"
stock_available: "{{ state_attr(trigger.to_state.entity_id, 'stock_available') }}"
price: "{{ state_attr(trigger.to_state.entity_id, 'price') }}"
name: "{{ state_attr(trigger.to_state.entity_id, 'friendly_name') }}"
action:
- service: notify.mobile_app_peter_iphone
data:
message: "TooGoodToGo"
title: "Stock: {{ stock }}, Price: {{ price }}, Name: {{ name }} "
So why do you put lowercase true/false for the from:
and to:
?
Maybe it doesn’t trigger when you change it yourself vut only when the sensor attribute actually changes.
poudenes
(Poudenes)
January 11, 2021, 12:42pm
5
When I removed the 3 lines:
from: 'false'
to: 'true'
attribute: stock_available
The trigger is working.
I change it myself and then I get notification … so it must work I guess…
123
(Taras)
January 11, 2021, 12:50pm
6
Does it work if you remove the quotes? Without quotes it’s no longer a string but a boolean value.
poudenes
(Poudenes)
January 11, 2021, 12:53pm
7
Is not working also.
Also tried it with 1 entity. Didn’t work also…
- alias: "ToGoodToGo - All shops"
trigger:
- platform: state
entity_id: sensor.toogoodtogo_broodhuys_meijer_magic_box
from: 'false'
to: 'true'
attribute: stock_available
- alias: "ToGoodToGo - All shops"
trigger:
- platform: state
entity_id: sensor.toogoodtogo_broodhuys_meijer_magic_box
from: false
to: true
attribute: stock_available
123
(Taras)
January 11, 2021, 12:58pm
8
Just out of curiosity, how does the attribute’s value appear in Developer tools > States? As lowercase true
or propercase True
?
poudenes
(Poudenes)
January 11, 2021, 1:14pm
9
This is whole list of all attributes:
price: 4.99
stock_available: false
url: http://share.toogoodtogo.com/item/9159
unit_of_measurement: portions
friendly_name: Broodhuys Meijer
icon: mdi:food-off
templates:
icon_color: 'if (state === "on") return "rgba(251,214,67,1)"; return "rgba(71,116,157,1)";'
123
(Taras)
January 11, 2021, 1:22pm
10
I suspect the State Trigger, when combined with attribute
, doesn’t know how to support an attribute value with a boolean type.
You could also ignore the from/to in the trigger and add it as conditiom instead.
poudenes
(Poudenes)
January 11, 2021, 1:31pm
12
Tried that as well. But there my knowledge is lost… What I tried I didn’t get it work.
Struggle with the code… If you can help me I can try that
This is what I tried:
condition: "{{ trigger.to_state.attributes.stock_available == 'true' }}"
123
(Taras)
January 11, 2021, 1:40pm
13
In the template, remove the quotes from 'true'
. If the attribute’s type is boolean, it should work.
Try this,
condition: "{{ trigger.to_state.state.attributes.stock_available == true }}"
If the boolean is recognized correctly it should work like this as well:
condition: "{{ trigger.to_state.state.attributes.stock_available }}"
poudenes
(Poudenes)
January 11, 2021, 2:33pm
15
Its so strange. its not working.
I have a second automation. without all the attribute criteria. So when I change a sensor I get notification.
Only from that automation I receive things.
Nothing from the other with criteria when sensors goes from false to true…
If I change with False/false True/true the other test one is working…
very strange
123
(Taras)
January 11, 2021, 2:39pm
16
In the Template Editor, this should return False if the attribute’s type is not a string.
{{ state_attr('sensor.toogoodtogo_broodhuys_meijer_magic_box', 'stock_available') is string }}
If it’s not a string then it stands to reason it must be a boolean. Yet it failed a direct comparison to a boolean.
poudenes
(Poudenes)
January 11, 2021, 2:49pm
17
{{ state_attr('sensor.toogoodtogo_broodhuys_meijer_magic_box', 'stock_available') is string }}
output:
false
But when I change the value to “testest” then I get:
true
Tried it also without is string:
{{ state_attr('sensor.toogoodtogo_broodhuys_meijer_magic_box', 'stock_available') }}
output:
false
But when I change the value to “testest” then I get:
false
How do you change the value? As I said before, it probably doesn’t trigger on this manual change.
poudenes
(Poudenes)
January 11, 2021, 2:54pm
19
using developer tool > states > states attribute
change it there.
i change everything back with
from: 'false'
to: 'true'
attribute: stock_available
and gonna wait when system change the value…
I always thought you can check things by edit the value yourself
poudenes
(Poudenes)
January 11, 2021, 3:33pm
20
Got 4 updates by system itself. Every time I change a option that was given above.
none of them work…
yes, I did reload automation after every change… haha
EDIT: Wait a minute… there is one solution that works:
###########################################################################################
# NOTIFY ME WHEN BOXES ARE IN STOCK AT TOGOODTOGO
###########################################################################################
- alias: "ToGoodToGo - All shops"
trigger:
- platform: state
entity_id:
- sensor.toogoodtogo_broodhuys_meijer_magic_box
- sensor.toogoodtogo_albert_heijn_amsterdamseweg_amstelveen_magic_box
- sensor.toogoodtogo_albert_heijn_to_go_amsterdam_wtc_magic_box
- sensor.toogoodtogo_boulangerie_noe_gustav_mahlerlaan_amsterdam
- sensor.toogoodtogo_de_drie_graefjes_stadionplein_amsterdam
- sensor.toogoodtogo_hema_gelderlandplein
- sensor.toogoodtogo_lidl_amsterdamseweg_188_groente_fruit_box
- sensor.toogoodtogo_lidl_bankrashof_groente_fruit_box
- sensor.toogoodtogo_starbucks_gustav_mahler_amsterdam
- sensor.toogoodtogo_sushi_time_wtc_amsterdam_magic_box
- sensor.toogoodtogo_the_roastary_magic_box
- sensor.toogoodtogo_poke_perfect_zuidas_magic_box
- sensor.toogoodtogo_juicebrothers_gustav_mahlerlaan_magic_box
- sensor.toogoodtogo_le_pain_quotidien_gelderlandplein_magic_box
- sensor.toogoodtogo_stadsbakker_jongejans_gelderlandplein_magic_box
condition: "{{ trigger.to_state.attributes.stock_available == true }}"
variables:
stock: "{{ states(trigger.to_state.entity_id) }}"
stock_available: "{{ state_attr(trigger.to_state.entity_id, 'stock_available') }}"
price: "{{ state_attr(trigger.to_state.entity_id, 'price') }}"
name: "{{ state_attr(trigger.to_state.entity_id, 'friendly_name') }}"
action:
- service: notify.mobile_app_peter_iphone
data:
message: "TooGoodToGo"
title: "Stock: {{ stock }}, Price: {{ price }}, Name: {{ name }} "
YES YES
1 Like