Hello everyone! there was a few months of headaches with the insteon switches and the 3w states situation.
If you don’t have insteon: you can link one switch or dimmer with anyone on the house, so you can made virtual 3w and works instantly.
The Problem:
-
When you push the switch with the main charge of light HA receives the state change, the 3w linked changes states on real life but HA will not notice cos this changes are not reported to the hub by default.
-
When you push a 3w HA see the 3w change of state but not the main charge new state.
-
The insteon HUB (v2) it’s very laggy, slow as hell, so the requests have to be the minimum to not overload it.
-
The regular automation included in HA require to made constant changes (requests) to the hub to change thing that already are on the desired state, the HUB overload.
-
Te regular Automation included in HA makes hard to program a 4 way or 5 way system, for a 4 way needs 8 automations with several HUB unnecessary requests.
-
The master on INSTEON, @teharris1 (Read this please) made an excellent upgrade recently so you can trigger scenes on the hub (the hub stores the linked switches as scenes), but in my case fails constantly and overload the hub with only 2 or 3 tries.
My Tries:
I believe a made everything was wrote. Here some of my experience.
- Regular Automation: FAIL, HUB Overload, massive work and overpopulation on Automation menu.
- Node RED: copying the regular automation science on NR was the same overload plus delays cos NR use webhooks to pull states. (wait, this will be our hero)
- Insteon to Mqtt: @TD22057 wrote and very useful and impressive library to convert the insteon msg to MQTT protocol, i tried, it’s not compatible with my hub, i bought a compatible interface, works but was to hard and i’m not so familiar with MQTT protocol, i’m strictly a newie on this and i want a solution that works with my hub, laggy hub with easy interface.
- Scene Triggering using the new capabilities of the native HA insteon library: works some times, overload the hub in my case.
Theres no more.
So i found an idea from @ronschaeffer just here
Was not insteon, but the situation sounds familiar to me. The key!
This method was tested on switches only, not dimmers, please share if you improved to used with dimmers
This is a step by step solution.
The Solution:
- Have to reflect the real state of the switch (all of them)
- Have to made only the necessary requests to the hub.
- Have to be scalable to N ways.
Lets do this:
Preparation:
- All the linked switches have to be tested in the real life so the states match every time in the reality.
- Write on paper the links.
- In my case i have Switchs with the main charge (master) and switch(es) and/or dimmers as slaves.
On HA:
Optional:
If you are using Dimmers as 3w of a switch i recommend made a template switch with the state of the dimmer, so the dimming bright level won’t affect the system.
In my code my dimmer is light.3w_entrada
My template switch is 3w_entrada_sw
- platform: template
switches:
3w_entrada_sw:
friendly_name: "3w Entrada Sw"
value_template: "{{ is_state('light.3w_entrada', 'on') }}"
turn_on:
service: light.turn_on
data:
entity_id: light.3w_entrada
turn_off:
service: light.turn_off
data:
entity_id: light.3w_entrada
- On your configuration.yaml Create an input_boolean for each master you are dealing with. This will help to know on the future if the light it’s been toggle from the real life or HA.
input_boolean:
luz_entrada:
name: Luz Entrada Virtual
-
In your user options create a long life TOKEN, name it as you wish. (copy and save on a secure place, basically its a master key to your HA instance)
-
Install NODE-RED
Programming:
Let say you have a simple configuration of light: ONE master and ONE slave, linked.
- Create one node of “events: state” for each linked device, plus one state node for the input_boolean.
- Create 2 Call Service node one connected to each output of the MASTER state node.
The connected to Master ON will turn_on the input_boolean switch. The other one will turn_off.
- Connect the ON and OFF outputs of the MAIN and Slaves States Nodes to the input of a function node (one for each of the state nodes).
Set the Function node as:
if(flow.get('flag') === true)
{
return null;
}
else
{
let flag=flow.get('flag') || true;
flow.set('flag',flag);
if(msg.payload=="on")
{
msg.payload={"state":"on"};
}
else
{
msg.payload={"state":"off"};
}
return msg;
}
- Create an HTTP REQUEST NODE for each MASTER AND SLAVE devices. Configure as follow:
Method: Post
URL: "https://your.ha.ip:8123/api/states/light.3w_entrada" or the entity you are setting up Without Quotes
Use Autotication: Bearer
Token: PASTEYOURLONGLIFETOKEN
- Connect the input to the output of the other switch. The Slaves always reports to the master and the other slaves, the master to all slaves.
For Example:
-
Connect the output of the httpPOST to a delay node (1 sec).
-
Connect to a Function Node with the code:
flow.set('flag',false);
msg.payload=flow.get('flag')
return msg;
CAREFUL: if you have severals slaves connected to the master you have to connect the HTTP post in parallel.
Almost ready:
-
Connect 2 Current State Nodes on the ON and OFF output of the input_boolean, for the ON output: check if the MASTER is off. For the OFF output, check if the MASTER is ON.
-
On the true output of each one connect a Function Node with the code:
let flag=flow.get('flag') || true;
flow.set('flag',flag);
msg.payload=flag;
return msg;
- To each Function node connector a Call Service Node to turn ON or OFF the switches.
Here the dirty job. the Hub v2 its very slow sending the orders. So we’ll ask him to turn off or on all of the entities in relation with this light fixture.
And the most important: Output Location: msg.payload.
- For every entity on this list create a WAIT UNTIL node and made the set for each device. Timeout at 5 sec is good. The trick is this: state is: expression
The code of the expression is:
$substringAfter($lookup(payload, "service"), "_")
The connection is in series and in the same order you locate them in the Call Service Node.
- Create a Call Service Node and configure as:
{
"message": "The insteon hub fails on the last order, reset the hub to best performance"
}
Connect the input of the TIMEOUT outputs of the WAIT UNTIL nodes.
- Finally create a FUNCTION node with the code:
flow.set('flag',false);
msg.payload=flow.get('flag')
return msg;
Connect the input to the both outputs of the last WAIT UNTIL and to notification service output.
UPDATE: connect the both outputs of every WAIT node to the next WAIT or (in case of the last WAIT) to the Function FALSE. Prevent fails on API send notification breaks the program.
The entire flow have to be like:
FrontEnd
On your frontend yo have to use the input_boolean instead the regular entity. In this case the LOVELACE button card won’t change the color of the card when toggle, you need to setup custom_ui or custom:button_card
Again i’m a newie on this, if you improve the code please share
Now the Request: @teharris1 this method solved my problems with the 3w perfectly but, as you know the insteon has the skill of trigger the off scene when the switch was already off, with my method if the insteon entity has an undefined state (forced) i can emulate this. You can see it? if i can force a undefined state of the entity without changing my input_boolean, HA will detect the change of state to OFF when was already off and trigger the 3w’s.
Thanks for your time and please share your Improvements of this!