Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle fuction #404

Closed
agoralive opened this issue Feb 25, 2019 · 12 comments
Closed

Toggle fuction #404

agoralive opened this issue Feb 25, 2019 · 12 comments

Comments

@agoralive
Copy link

Is there a way to create a "simple" Node-Red toggle button?

Perhaps a MQTT function which checks current state and then sends the opposite?

if state = on
then set state off
or if
stafe off
then set state on

The above is ABSOLUTELY now a correct code, but can anybody make one which works?

If the above is not possible could it perhaps be done by a MySQL db, where the latest state is stored in a DB which is then checked before choosing the state we wish for?

I would prefer if somebody could direct me to the DB solution, because I have hardware button which also is controlling the light, and would like to whole system to work together.

@sidoh
Copy link
Owner

sidoh commented Feb 25, 2019

(assumed) state is stored internally and is accessible through the REST API and retained MQTT messages. No need to keep track of it externally.

Where I have things that toggle on/off state, I just use HomeAssistant's toggle functionality.

Does this help?

@agoralive
Copy link
Author

No

I have a Xiaomi switch which controls the lights by converting the payload into a MQTT message, and whenever, a button in the NodeRed dashboard, the original panels or the remotes are turning lights on/off I would like to be able to change the state of a specific zone using a "button" in NodeRed, but this button does not know if the latest state is on or off.

I think I will try to find a solution where a db entry will set latest state, and then the NodeRed dashboard button will read this, react by choosing the opposite state, and then save the new state to the db for the next control and send an "update" MQTT for the ESP8266_milight_hub

@sidoh
Copy link
Owner

sidoh commented Feb 25, 2019

There's no need to add another layer that keeps track of state. espMH already tracks state.

@agoralive
Copy link
Author

Yes is keeps track but dosen't allow for "just" a state change. It is not possible to send a "toggle" command which changes the from "on to off" or "off to on".

Such an option would make it compatible with external button's AND Node-Red dashboard "button".

For instance the Sonoff custom firmware Tasmota, has such a function which allows for three (3) different devices to be controlled from one (1) Xiaomi wireless button (single, double and long press). This eliminating the need for a function, a db, and programming skills for the users. (Not that this is not good enough to be capable of, but not always an option)

@garmck
Copy link

garmck commented Feb 26, 2019

I think you need to raise an issue or look up details for NodeRed.
I am doing exactly what you describe with a Xiaomi button, MiLight B4 panel and MiLight remote using MQTT to track states between all those devices.
It seems you issue is a limitation of node red. Not espMH

@agoralive
Copy link
Author

agoralive commented Feb 26, 2019

@garmck Perfect

How do you update the MQTT statement for the bulbs, in order for the "button" in NodeRed Dashboard to switch off, in case the bulb is already on, by one of your hardware remotes? Keep in mind that the "button" in NodeRed thinks that the bulb is off (as this was the last switch it made)

Simplyfied:

Node-red button turns on bulb (Bulb = ON - button = ON)
Hardware remote turn off bulb (Bulb OFF - button = ON)
Node-red button is pushed again, I want to bulb to turn ON but the "button" thinks the bulb is OFF and it sends an ON message.

How did you update the "button" state in Node-Red?

@garmck
Copy link

garmck commented Feb 27, 2019

I'm not using NodeRed. As stated this maybe a limitation of NodeRed NOT espMH.

In espMH for MQTT settings have you configured topic, update topic and state topic ?

@agoralive
Copy link
Author

Yes everything works perfectly. There are no issues with, espMH, MQTT, Node-Red, Xiaomi, Sonoff's, etc

Only looking for a "toggle" function, which makes a button possible or a way to update a switch to actual state in Node-Red dashboard

@agoralive
Copy link
Author

If anybody has any idea's please share. I am looking for something like this:

mosquitto_pub -t cmnd/device_id/POWER -m toggle

This command works with hardware which uses Tasmota software

@sidoh
Copy link
Owner

sidoh commented Mar 2, 2019

It's not an unreasonable ask, although it'd look something like

mosquitto_pub -t milight/command/0x1/rgb_cct/1 -m {"command":"toggle"}

@sidoh
Copy link
Owner

sidoh commented Mar 3, 2019

Added in 1.9.0-dev8.

@sidoh sidoh added this to the 1.9.0 milestone Mar 3, 2019
@agoralive
Copy link
Author

@sidoh

I have not tried this yet, but THANKS!!!!!!!!!!!!!!!!

@sidoh sidoh mentioned this issue May 27, 2019
@sidoh sidoh closed this as completed May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants