Problem with “Irrigation Unlimited HACS Integration”. Enabled attribute

Hello,

I’m trying to make a script to water my garden based on the irrigation unlimited HACS integration. This is just to put you in context.

In this integration I have a binary sensor called binary_sensor.irrigation_unlimited_c1_z1 with the next attributes:

index: 0
enabled: false
status: disabled
schedule_count: 1
schedules: ''
adjustment: None
current_schedule: not running
percent_complete: 0
next_schedule: 1
next_name: Primavera
next_start: '2021-03-02T08:50:00+01:00'
next_duration: '0:05:00'
today_total: 14.4
friendly_name: Zona 1
icon: 'mdi:circle-off-outline'

I have created a script, and I want to make some actions if the enabled property is true or false, but I don’t know why, the actions are never executed regardless the state of the ‘enabled’ property.

The script is this:

alias: 'test'
sequence:
  - service: notify.telegram_notifier
    data:
      message: before
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.irrigation_unlimited_c1_m
            attribute: enabled
            state: 'false'
        sequence:
          - service: notify.telegram_notifier
            data:
              message: inside
    default: []
  - service: notify.telegram_notifier
    data:
      message: after

I get in my mobile:

before
after

but never the ‘inside’ message.

Any help will be welcomed.

binary_sensor states are ‘on’ or ‘off’ - that’s it - nothing else

Goto Developers Tools - States
And look what the ‘state’ currently is (it will be one or the other)

eg : -

1 Like

Do you mean that what I want to do is not possible? :roll_eyes:

So, how could I check the values of the attributes of the sensor?

No, I didn’t say that
Merely because (say) the front-end shows the sensor as ‘open’ or ‘closed’ the REAL state (of a binary_sensor) will be ‘on’ or ‘off’.
You have to check and thus interpret

Extra: you just replied ‘to the thread’
As the thread owner, you get a notification (no one else does)
If you reply ‘to me’ (the reply button in the bottom right of my post) then ‘I’ get a notification too.
Or you ‘could’ tag me i.e. @Mutt but be careful doing that as it’s considered rude in most circumstances

My problem is that I have to check that the sensor is enabled before trying to toggle its state.

Eh ?

Most sensors report a value that is representative of a state it has detected in the field.
You should not be able to write to such, you should only be able to read from it.
Things you write to are like switches or lights or say a thermostat where you can write a value such that the thermostat switches above/below this value etc.

What type of sensor is it ? (I;m assuming an esp32 or similar ?)

You also need to format your code according to point 11 of the sticky : -

Try using a template that state for condition like this.

alias: 'test'
sequence:
  - service: notify.telegram_notifier
    data:
      message: before
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ state_attr('binary_sensor.irrigation_unlimited_c1_m',
              'enabled') == "false" }} 
        sequence:
          - service: notify.telegram_notifier
            data:
              message: inside
    default: []
  - service: notify.telegram_notifier
    data:
      message: after
1 Like

Irrigation unlimited provides a service that enables manual irrigation. When this service is called, the status of the binary_sensor is changed. I meant changing the status of the sensor with this service.

I’ve tried that but with no success.

I’ve tried the next templates in Developer tools -> templates:

{{ state_attr('binary_sensor.irrigation_unlimited_c1_z1', 'enabled') }}
{{ state_attr('binary_sensor.irrigation_unlimited_c1_m', 'enabled') == "false" }} 

And the result is:

False
False

:roll_eyes:

These are just print statements ???
:confused:

Edit: jinja2 is a print language, you should be using your integrations api
Edit2: {{ ‘Hello World’ }} just prints ‘Hello World’ hence print statement
Edit3: and your two statements above resolve to true or false (both false in this case and are printed as such)

Sorry, what do you mean with print statements? :flushed:

Try removing the quotes surrounding the word false.

This is a string: 'false'

This is a boolean: false

It’s the state of an attribute though.

Correct; my original post was mistaken and I quickly deleted it to prevent misleading others. However, while re-editing it, the original was revealed again … long enough that others saw it. Anyway, the original is gone now (unless someone bothers to examine the post’s history).

I would guess that you need some specialist help from someone familiar with your “Irrigation Unlimited HACS Integration” - I would suggest you either find a thread concerning that (search) or you change the name of this thread to attract those specialists (the pencil you see next to the title) - I’d suggest "Help needed “Irrigation Unlimited HACS Integration” " or something similar

1 Like

You’re right. I think it seems an Irrigation unlimited related problem.

Same behaviour :roll_eyes:

You are saying that the current state of the enabled attribute is false yet none of these report True in the Template Editor?

{{ state_attr('binary_sensor.irrigation_unlimited_c1_m', 'enabled') == false }} 
{{ state_attr('binary_sensor.irrigation_unlimited_c1_z1', 'enabled') == False }}
{{ state_attr('binary_sensor.irrigation_unlimited_c1_m', 'enabled') == "false" }} 
1 Like

Yes!!

The second one reports True.

That was the problem.

Thank you very much to all of you!

1 Like

I used to think the system understood booleans to be true/false or True/False but it’s a bit more nuanced than that. In this case, the attribute’s value is handled as a python boolean
(due to type inference) and so it’s exclusively True/False.