Input_boolean without knowing the current state of the entity

Hi Everyone,

I am not sure how to overcome a challenge and would really appreciate any suggestions or comments, as I feel I may be missing fundamental info about HA.

Short Summary:
My plan is to control the projector through IR blaster (Broadlink mini rm3). This one is configured and working properly. I decided to handle the functionality in node-red, as for turning the projector off I need to send the “turn off” command twice in a row.

Challenge:
I would like now to communicate the HA with Node-red. Normally I would create an input_boolean for that. Unfortunately, since I am not able to check the real status of the projector I would like to always have the possibility to run the “turn off” and “turn on” action. (it can be useful when I am out of the home and I want to make sure the projector is turned off)

in very simple words, instead of typical UI representation (toggle button) I would prefer to have something similar to this:
image

I tried another approach - to create buttons that would trigger input_boolean.turn_off or input_boolean.turn_on actions. Unfortunately, if the input_boolean is already off the action turn_off will not be visible under node-red.

My ideas to overcome the challenge:

  1. Change the way how the input_boolean is represented (from toggle button to two lightening buttons for on/off)
  2. Use other elements instead of input_boolean - Which one?
  3. Create buttons and attach to them some dummy services that can be always read by node-red.

I would appreciate any comments/ideas:slight_smile:
Thank you!

you can make a template switch that links to the turn on and turn off service and use that in the UI.

switch:
  projector_on_off:
    turn_on:
      service: switch.turn_on
      target:
        entity_id: switch.projector
    turn_off:
      service: switch.turn_off
      target:
        entity_id: switch.projector
1 Like

But the fact is that HA has no way of knowing whether your projector is on or off. The projector itself is not integrated with HA - only the Broadlink.

This is always a problem with toggle buttons, particularly if the device involved can still be operated manually. I have a couple of lights like this (like you I use input_booleans to represent them in the UI). I have hidden the remotes, but they still get out of sync occasionally.

What happens after a power cut? Does the projector resume its earlier status, or does it default to off? If the former, you could use a properly integrated smart plug to switch it on and off and use the status of the plug in your UI.

Besides using a smart plug for on/off purposes, one which returns the energy power consumption can also be used to detect whether what is attached to it is actually on or off.

1 Like

Hadn’t thought of that - can you recommend one?

“Recommend” is a strong word, but I have both a xiaomi Mi Smart Zigbee Plug and a random Tuya Zigbee plug (ZigBee – prise de courant 3.0 W, 16a, avec minuterie vocale, pour maison connectée, fonctionne avec Alexa et Google, 3500 | AliExpress) that does that.

1 Like

Hi petro,

thanks for the recommendation. I was not aware that a template_switch will immediately have this graphical representation I was looking for :slight_smile:
image

I am a step closer to a solution, but overall it seems the approach I took was wrong - in the node-red, I can track only the “event: state” which will not change anyway, as it is already off. I could potentially track all events but I believe it wouldn’t be very efficient.

I will need to look for an option to have something like two monostatic/push-buttons in HA that could trigger a state change that I could listen for in node-red…

Is there any other way or I am overcomplicating stuff?

to be honest, it seems like you’re overcomplicating this. What is the endgoal of this automatino. ALl you stated is that you need to send 2 turn offs in a row… which you can just create a script for. What’s the actual endgoal with this node-red automation.

Petro,

My preference is to create and maintain all automation through node-red - I find it simply more powerful and flexible.

I did some checks and what you have suggested solves my problem fully.

  1. Using template switch instead of input_boolean allows me to multiple times click the “off” or “on” button which can trigger any type of script.

this is how it looks now:

- platform: template
  switches:
    projector:
      turn_on:
        service: script.projector_turn_on
      turn_off:
        service: script.projector_turn_off

2 option a. Script will allow me to do basically anything including sending twice “turn off” commands with a delay in between (required by projector)

2 option b. I may create dummy scripts that only trigger a 1ms delay and in node-red I can set a listener to state_changed of this script - it feels very nasty, but this way I can draft all functionality in node-red which is my preference. If you can fink of any other approach please let me know

huge thanks for help petro!:slight_smile:

You can just perform the script inside the turn_on service or turn_off service. You don’t need the scripts.

- platform: template
  switches:
    projector:
      turn_on:
      - service: switch.turn_on
        target:
          entity_id: switch.projector
      - delay: "00:00:01"
      - service: switch.turn_on
        target:
          entity_id: switch.projector
      turn_off:
      - service: switch.turn_off
        target:
          entity_id: switch.projector
      - delay: "00:00:01"
      - service: switch.turn_off
        target:
          entity_id: switch.projector
1 Like