Rest sensor trigger not working correctly

Hi,

I have a json file of the following example format, options are true or false for each item:

{
    "first": true,
    "second": false,
    "third": false
}

I am using the following sensor:

  - platform: rest
    name: test
    resource: http://192.168.20.2/test.txt
    json_attributes:
      - first
      - second
      - third

Here is the code I am using for the trigger:

- id: '201'
  alias: Test Alerts
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.test
    attribute: first
    to: 'true'
    from: 'false'
   action:
  - service: notify.mobile_app_nameofphone
    data:
      message: First changed from false to true

I have tried false, ‘false’ and “false” in the trigger (boolean vs string?) but am unable to get the trigger to execute on a state change.

Any thoughts on how to get this to execute correctly?

Thanks,
Peter

Both of those are strings. With no quotes they will be booleans.

Hi,

I did try no quotes, but that does not work either.

The rest sensor does seem to be working correctly and detecting the change in state - below is a snapshot from the Configuration/Entities/(select entity, slider icon in top right) window:

September 29, 2020
9:30:28 AM
Changed to { "first": true, "second": false, "third": false }
first true
second false
third false

This is the state change that should be detected by the trigger, but still no luck (no evidence of trigger executing, Configuration/Automations does not show a last trigger time).

I have been trying to narrow down the problem further through debug… The rest sensor appears to be working correctly, and the transition to the new state is detected when attribute ‘first’ changes from false to true:

2020-09-29 21:00:08 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2841881064] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=sensor.test, **old_state**=<state sensor.test={
    **"first": false,**
    "second": false,
    "third": false
}; first=False, second=False, third=False, friendly_name=test @ 2020-09-29T20:58:08.009583-04:00>, **new_state**=<state sensor.test={
    **"first": true,**
    "second": false,
    "third": false
}; first=True, second=False, third=False, friendly_name=test @ 2020-09-29T21:00:08.017779-04:00>>}

However, my trigger is still failing to detect the from: False to: True transition on the ‘sensor.test’ entity and ‘first’ attribute. I have tried False/True, false/true, ‘false’/‘true’ for the from: to: in the trigger but none work. I have also tried leaving the from: field blank and just using True in the to: field but this doesn’t work either.

Any ideas?

Thanks,
Peter

OK, some further progress after hours of trying to get this going… In Developer Tools/Template, I can see the state changing with the code below, so the json file and rest sensor appear to be working correctly:

{{ is_state_attr('sensor.test', 'first', True) }}

(this reports False if ‘first’ is set to false in the json file, True if ‘first’ is set to true)

However my trigger:

Type = State
Entity = sensor.test
Attribute = first
From = False
To = True

is still not working?

If I can’t do what I am trying to do with the attributes, any ideas on alternative methods I could try?

Thanks,
Peter