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

Flip-Flop Implementation? #694

Closed
rei-vilo opened this issue Feb 19, 2018 · 12 comments
Closed

Flip-Flop Implementation? #694

rei-vilo opened this issue Feb 19, 2018 · 12 comments

Comments

@rei-vilo
Copy link

rei-vilo commented Feb 19, 2018

I have the following configuration:

  • one push button (GPIO 18) and
  • a LED (GPIO 17)

capture 2018-02-19 a 21 05 03

I would like to toggle the LED with the push button acting as a "flip-flop", e.g.

  • Initial state: LED is off.
  • Push button pressed then released: LED turns on.
  • Push button pressed then released: LED turns off.
  • ...

How to achieve that? How many rules, and which ones, do I need to define?

This question might be related to #693.

@kgiori
Copy link
Contributor

kgiori commented Feb 20, 2018

Currently the rules engine shows properties for web thing types, but not the ability to track or trigger an "action". The onOffSwitch thing type definition has an "action" called "toggle" which changes its "on" property to the alternate state. The onOffLight does not have such an action in its definition. Maybe it should? It seems that the type of rule you describe wanting would work if the toggle action of one device was tied to the toggle action of another device.

If a pushbutton is attached to GPIO 18, then instead of defining it as an onOffSwitch, I would rather see a new thing type defined that better describes how a pushbutton works. A pushbutton "toggle" event would be triggered by "off-on-off" (low high low) changes in voltage on the pin, not a simple off-on or on-off (low to high, or high to low).

Even without a pushbutton thing type, you could detect the pushbutton off-on transition (by detecting the "on" state becoming true). What's missing is an onOffLight action of "toggle", and the rules engine allowing you to select an action as the triggered event.

@rei-vilo
Copy link
Author

Thank you for the explanations. I know Rules are at an early stage of beta.

An action is just a change of state. The priority of state over action should be clearly documented to avoid any misunderstanding, as State and action are common concepts, most of the time implicit.

On the screen-shot below, the rule says If Button 18 is off then turn LED 17 off.
36395963-16d0396a-15bc-11e8-91e4-1e9ef6f8b9a5

So adding If Button 18 is off then change state of LED 17 (change off to on, change on to off) would fit the flip-flop task.

How do those explanations match with the example provided in #693?

@rei-vilo
Copy link
Author

@mrstegeman The ticket has been changed to closed then done.

  • Could you please explain how to use this feature?
  • In which release is it going to be available?
  • Where can I find the related documentation?

Thank you!

@mrstegeman
Copy link
Contributor

I do this exact thing with some lights in my house, using a Flic button.

  • Rule 1: If light is off and button pressed, turn light on
  • Rule 2: If light is on and button pressed, turn light off

@rei-vilo
Copy link
Author

Thanks!

Even better with screen-shots:

Capture d’écran 2019-12-28 à 19 07 08

Capture d’écran 2019-12-28 à 19 07 13

@mrstegeman
Copy link
Contributor

Exactly! Apologies for the lack of comments.

@rei-vilo
Copy link
Author

No problem, I posted the screen-shots so other users can share the solution.

Actually, the solution is provided by the rule engine that accepts multiple conditions.

I didn't know the rule engine offered that feature. I discovered it today.

Maybe room for a pointer to the rule engine documentation?

@mrstegeman
Copy link
Contributor

@rei-vilo
Copy link
Author

For coming visitors: look at section IV. Rules: Automate Your Home

When you have more than one input parameter, you can select “And” or “Or” as the logical condition to tie together the input parameters.

@freaktechnik
Copy link
Contributor

Note that this approach can lead to infinite loops if both conditions are properties. So it is important that one of them is an event (and I think that I infact had a ticket open for events being able to still cause momentary loops)

@rei-vilo
Copy link
Author

Yes, I am not fully happy with this solution.

  • I hope the press event corresponds to the button going from released to pressed, not the the press state.

This is similar to issue #693 Question: Do Rules Transfer State or Action and thread
Discussion: Possible Confusion between State and Action on Devices

  • Also, the button needs to be debounced properly.

@mrstegeman
Copy link
Contributor

@rei-vilo All of that is entirely dependent on the device and add-on.

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

5 participants