home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.46k stars 29.4k forks source link

State changed triggered when state is not changed #6299

Closed thrust15 closed 7 years ago

thrust15 commented 7 years ago

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version): 0.39.1

Python release (python3 --version): 3.4.2

Component/platform: Device_tracker, Sensor

Description of problem: on 0.39.1 I have different behaviour of states that 0.38.3. When my z-wave wall plug isn't using any power but is reporting its state (Essentially updating 0.0w to 0.0w), a state changed event is fired, which it didn't on 0.38.3.

The same behaviour i have with owntracks. When updating my location, but i'm still in my home zone, a state changed event is fired. (device_tracker updates gps coordinates, but doesn't change it's state (from home to home). Which triggers my 'getting home' automation again.

Expected: State changed events only when states actually change.

Problem-relevant configuration.yaml entries and steps to reproduce:

- platform: template
  sensors:
    bob_wakker:
      value_template: '{{ ((as_timestamp(now()) - as_timestamp(states.sensor.bed_bob_power_14_4.last_changed) > 900)) and (states.sensor.bed_bob_power_14_4.state | float == 0) }}'
      friendly_name: 'Bob wakker'
      entity_id:
        - sensor.bed_bob_power_14_4
        - sensor.time

- alias: Thuiskomst Bob
  trigger:
    platform: state
    entity_id: device_tracker.bob_nd
    to: 'home'
  condition:
    condition: state
    entity_id: binary_sensor.alice_actief
    state: 'off'
  action:
    service: script.turn_on
    entity_id: script.home
  1. Z-wave wall plug reports an update
  2. Homeassistant updates values of wall plug
  3. Attribute last_changed is set to current time

  4. State of Device_tracker is set to 'home'
  5. Open owntracks
  6. Manually update location while home
  7. Automation Thuiskomst Bob triggers

Traceback (if applicable):

NA

Additional info: I reverted back to 0.38.4, and a quick check shows that the device_tracker does not update state when not changing zones, but is updating coordinates. (I already stopped the periodic reports of my wall plug directly in z-wave so I cannot easily verify that)

nordicblue commented 7 years ago

Been anxiously waiting to see any movement on this, or a confirmation that it is indeed an issue with 0.39 or above. I opted not to upgrade because of this ticket, curious to know if anyone else on the latest release is seeing this issue. I too have a lot of triggers on state change and if they fired off on each reported mqtt publish, where the value didn't actually change, this would be a major headache for me.

thrust15 commented 7 years ago

Same goes for media player (Apple TV)

I have to configure the following triggers to ensure they don't constantly trigger (or use a template trigger)

- alias: Dim lights when apple tv playing
  trigger:
    - platform: state
      entity_id: media_player.apple_tv
      from: 'paused'
      to: 'playing'
    - platform: state
      entity_id: media_player.apple_tv
      from: 'idle'
      to: 'playing'

Instead of (which I think is cleaner)

- alias: Dim lights when apple tv playing
  trigger:
    - platform: state
      entity_id: media_player.apple_tv
      to: 'playing'
nordicblue commented 7 years ago

I ended up doing the same last night, but then got to the zone triggers and realized that there is no option for that. It is either enter or leave, can't do from to to in zones.

On Mar 3, 2017 3:09 AM, "thrust15" notifications@github.com wrote:

Same goes for media player (Apple TV)

I have to configure the following triggers to ensure they don't constantly trigger (or use a template trigger)

  • alias: Dim lights when apple tv playing trigger:
    • platform: state entity_id: media_player.apple_tv from: 'paused' to: 'playing'
    • platform: state entity_id: media_player.apple_tv from: 'idle' to: 'playing'

Instead of (which I think is cleaner)

  • alias: Dim lights when apple tv playing trigger:
    • platform: state entity_id: media_player.apple_tv to: 'playing'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/home-assistant/home-assistant/issues/6299#issuecomment-283891916, or mute the thread https://github.com/notifications/unsubscribe-auth/AXxUsMsIxZmLsdPvqcuBJu7AUSv09d3Yks5rh8qigaJpZM4MOAK0 .

meltonbw commented 7 years ago

I have the same problem with my Chromecast automating my lights. I'd get constant firing of the automations that turn on and off my lights when playing. Looking at the log, it seems to happen every time HA gets an update from the Chromecast. This seems to depend on the kind and source of the media I'm playing (Comedy Central shows seem to send a lot of updates and make my lights go insane). I came up with this workaround using conditions for now...

    trigger:
      platform: state
      entity_id: media_player.living_room
      to: 'playing'
    condition:
      - condition: template
        value_template: '{{ trigger.from_state.state != "playing" }}'

and

    trigger:
      platform: state
      entity_id: media_player.living_room
      from: 'playing'
    condition:
      - condition: template
        value_template: '{{ trigger.to_state.state != "playing" }}'

It filters out the 'noise' and I no longer get any more odd triggers from my automations.

nordicblue commented 7 years ago

meltonbw, would this also work for zones?

i.e.:

meltonbw commented 7 years ago

Not sure, I don't use zones, but you can try. Worst case you get a bunch of errors in your log. The reference for what trigger data you can use in a template is here: https://home-assistant.io/docs/automation/templating/

nordicblue commented 7 years ago

I'll probably try and upgrade to the latest version this weekend and see what happens. Excited to try the new features. If I have to turn the zone automations off, until this is addressed, I guess not the end of the world

amelchio commented 7 years ago

This issue mentions several similar problems but it is not clear that all of them disappear by downgrading to 0.38(?)

Probably most of them are due to automations that hit the unexpected trigger behavior mentioned in #6499 (I can see that several of the examples here are constructed just like that).

The change in Z-wave between 0.38 and 0.39 could be due to #5844. In 0.39, Z-wave sensors apparently trigger periodically even if there is no change in state, heavily increasing the risk of hitting the #6499 trap.

pvizeli commented 7 years ago

You can use state trigger with from, to and it trigger only on state change. If you want also only Trigger once, use a template trigger.

thrust15 commented 7 years ago

For a complete overview I added some questions from #6499

@amelchio I already mentioned that this can be worked around by adding from states. It is not so easy though. For one thing, there is no practical way of knowing all possible from states. Typing them out is also a lot more verbose and error prone.

Numerous posts indicate that I am not at all alone in being confused by this. I even read the documentation but it does not help because we have state and then we have state.state and it is not clear that "the state" actually refers to the first one. This is not a documentation issue, though. The documentation would be fine if the code worked in an intuitive way.

So rather than just closing the ticket, could you take a minute to explain/justify the current behavior of running the action at unpredictable times? Maybe provide an example where it is useful? I think that would be enlightening to many, including me.

@qcryptic Im also inclined to agree. Having the automation get retriggered because of an attribute change while the state hasn't actually changed isn't what most people would expect.

pvizeli commented 7 years ago

https://home-assistant.io/docs/automation/trigger/#template-trigger If you will not happy with state trigger, use template trigger. All things work in same way inside has. That will not be change.

thrust15 commented 7 years ago

Hi @pvizeli

Can you explain why there is chosen to handle state triggers like it currently works?

In my opinion our suggestion is more intuitive, but there might be another reason I don't know of yet.

amelchio commented 7 years ago

So I tested the template trigger and, indeed, it works as expected: it fires just once for a state change. That is exactly what we ask for the state trigger so what's the problem? In fact it seems like the current situation is quite the opposite of "work in same way".

What is different between these two configurations, besides the first one being annoyingly verbose?

trigger:
  - platform: template
    value_template: "{% if is_state('media_player.apple_tv', 'playing') %}true{% endif %}"
trigger:
  - platform: state
    entity_id: media_player.apple_tv
    state: playing

@pvizeli It sounds like you want to close this discussion. A very good way to do that would be to explain why the current behavior is desirable (listing workarounds does not count as an explanation!). Then we could all go "aaaah", feel a bit silly and then carry on with other stuff.

pvizeli commented 7 years ago

The short way is {{ is_states('media_player.xy', 'playing') }}

pvizeli commented 7 years ago

The state trigger is for statemachine and trigger every time how a platform write to statemachine. So it decide the maintainer of this platform how that will trigger and not the hass core. The template trigger does only trigger once until it change the situation.

amelchio commented 7 years ago

Again, you describe how it works, not why it works like that. As of yet, no disadvantage of the change proposed in #6499 has been identified.

fanaticDavid commented 7 years ago

I just noticed the effect of this issue today. I have an Aeotec Multisensor 6 in my office, and I use its luminance sensor to turn on my desk lamps, or adjust their brightness, based on the luminance in the room. I use a single automation for this, and the Multisensor is set to report the luminance every 30 seconds.

During the day I expect this automation to fire frequently as the luminance in the room changes constantly. However, once it's dark outside this is no longer the case but a look at the logbook in HA shows that the automation was still being fired every 30 seconds.

This is what my logbook shows between 20:00 and 20:10:

schermafbeelding 2017-03-23 om 00 44 06

In my syslog, I find this within the same time frame:

Mar 22 20:00:06 Ra hass[19048]: #033[32m17-03-22 20:00:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:00:06.346856+01:00>, old_state=<state sensor.office_multi_luminance_3_3=4.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T19:59:34.811093+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:00:37 Ra hass[19048]: #033[32m17-03-22 20:00:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:00:37.883499+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:00:06.346856+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:01:09 Ra hass[19048]: #033[32m17-03-22 20:01:09 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:01:09.419977+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:00:37.883499+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:01:40 Ra hass[19048]: #033[32m17-03-22 20:01:40 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:01:40.955177+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:01:09.419977+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:02:12 Ra hass[19048]: #033[32m17-03-22 20:02:12 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:02:12.490253+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:01:40.955177+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:02:44 Ra hass[19048]: #033[32m17-03-22 20:02:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:02:44.025606+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:02:12.490253+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:03:15 Ra hass[19048]: #033[32m17-03-22 20:03:15 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:03:15.559241+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:02:44.025606+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:03:47 Ra hass[19048]: #033[32m17-03-22 20:03:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:03:47.093722+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:03:15.559241+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:04:18 Ra hass[19048]: #033[32m17-03-22 20:04:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:04:18.629631+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:03:47.093722+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:04:50 Ra hass[19048]: #033[32m17-03-22 20:04:50 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:04:50.171599+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:04:18.629631+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:05:21 Ra hass[19048]: #033[32m17-03-22 20:05:21 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:05:21.705629+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:04:50.171599+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:05:53 Ra hass[19048]: #033[32m17-03-22 20:05:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:05:53.242260+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:05:21.705629+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:06:24 Ra hass[19048]: #033[32m17-03-22 20:06:24 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:06:24.775122+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:05:53.242260+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:06:56 Ra hass[19048]: #033[32m17-03-22 20:06:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:06:56.321082+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:06:24.775122+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:07:27 Ra hass[19048]: #033[32m17-03-22 20:07:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:07:27.847533+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:06:56.321082+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:07:59 Ra hass[19048]: #033[32m17-03-22 20:07:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=4.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:07:59.387315+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:07:27.847533+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:08:30 Ra hass[19048]: #033[32m17-03-22 20:08:30 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:08:30.918226+01:00>, old_state=<state sensor.office_multi_luminance_3_3=4.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:07:59.387315+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:09:02 Ra hass[19048]: #033[32m17-03-22 20:09:02 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:09:02.459513+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:08:30.918226+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:09:33 Ra hass[19048]: #033[32m17-03-22 20:09:33 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:09:33.992405+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:09:02.459513+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:10:05 Ra hass[19048]: #033[32m17-03-22 20:10:05 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:10:05.530161+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:09:33.992405+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m
Mar 22 20:10:37 Ra hass[19048]: #033[32m17-03-22 20:10:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:10:37.067905+01:00>, old_state=<state sensor.office_multi_luminance_3_3=3.0; wake_up_interval=240, icon=mdi:white-balance-sunny, friendly_name=Luminance, unit_of_measurement=lux, node_id=3, battery_level=100 @ 2017-03-22T20:10:05.530161+01:00>, entity_id=sensor.office_multi_luminance_3_3>#033[0m

Tl;dr: for the 21 times the automation was fired, only 2 actual state changes occured: the luminance was at a constant 3.0 lux, it only changed to 4.0 lux once and then back again.

And I'm not even going to mention the amount of obsolete information that gets stored by the recorder this way (e.g. reporting a state "change" from 0.0 lux to 0.0 lux every 30 seconds all throughout the night)...

swbradshaw commented 7 years ago

I would agree that the state trigger does not work how you would expect, and also not as the documentation suggests. I think the documentation needs updating.

STATE TRIGGER Triggers when the state of tracked entities change.

This really comes down to the definition of state. I believe users are thinking the state as what is reported in HA in the States screen where it lists the entity and the state (open/closed/playing/etc). As @pvizeli mentioned above, the state trigger fires whenever a platform writes to the state machine. This could be attribute changes unrelated to the state that users are seeing. Because of this, I think the documentation is misleading and/or wrong.