State not working??
Moderators: grovkillen, Stuntteam, TD-er
State not working??
I have one led connected to GPIO12 on mega-20181208 configured linke this:
Devices name: LED
Switch type: Switch input
Switch Button Type: normal Switch
GPIO: GPIO12,
Values: State
If I change the status in tools page with the command like: GPIO,12,1 the led go on but in the page devices the value state do not change and I'm not able to check the state (alwais 0) in scripts
wrong behavior or bug? with the mega-20180822 work fine..
thankyou in advance
MArco
Devices name: LED
Switch type: Switch input
Switch Button Type: normal Switch
GPIO: GPIO12,
Values: State
If I change the status in tools page with the command like: GPIO,12,1 the led go on but in the page devices the value state do not change and I'm not able to check the state (alwais 0) in scripts
wrong behavior or bug? with the mega-20180822 work fine..
thankyou in advance
MArco
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Stare not working??
You shouldn't use a switch input device for a LED. If you want to know the state of the LED you should use a dummy device and set it's value using event.
Given that you use task number 10 for a dummy device called "LED" and it's value named "State" you could use this rule:
You can then use this command from whatever way you invoke the command:
Why you cannot use GPIO to do this? Because the system will not know that the GPIO command are not supposed to be used for switching device values.
Given that you use task number 10 for a dummy device called "LED" and it's value named "State" you could use this rule:
Code: Select all
On toggleLED Do
If [LED#State]=1
GPIO,12,0
Else
GPIO,12,1
EndIf
EndOn
On setLED Do
If %eventvalue% > 0
GPIO,12,1
TaskValueSet,10,1
Else
GPIO,12,0
TaskValueSet,10,0
EndIf
EndOn
Code: Select all
Event,toggleLED
or
Event,setLED=1
or
Event,setLED=0
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: State not working??
Hi,
I have the same problem as described by fra290 since I flashed v2.0_20181204. My setup is similar, a relay module connected to gpio 5 of a Wemos D1 mini . After returning back to v2.0_20181125 it is working again: state changes when setting gpio.
So the question is: what has changed?
regards-
Manfred
I have the same problem as described by fra290 since I flashed v2.0_20181204. My setup is similar, a relay module connected to gpio 5 of a Wemos D1 mini . After returning back to v2.0_20181125 it is working again: state changes when setting gpio.
So the question is: what has changed?
regards-
Manfred
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: State not working??
We're doing a cleanup of the P001 plugin (aka Switch input - Switch). So I wouldn't recommend updating if you are relying on the old plugin. Wait for the overhaul is completed. We want it to be 100% great for the upcoming stable release.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: State not working??
The changes to the Switch device plugin are discussed here:
https://github.com/letscontrolit/ESPEasy/issues/2112
Bottom line: Don't upgrade the firmware unless you are prepared to change rules and devices. With some feedback the developer could be encourage to restore backwards compatibility. So share your opinion in the github discussion if you want it back.
- Thomas
https://github.com/letscontrolit/ESPEasy/issues/2112
I don't agree. Some of us have been doing it (create switch devices to monitor output bits) for a long time. I first learned about this functionality in the ESPEz Sonoff Wiki. It appears it is an intentional feature that has been removed from the latest releases.You shouldn't use a switch input device for a LED. If you want to know the state of the LED you should use a dummy device and set it's value using event.
Bottom line: Don't upgrade the firmware unless you are prepared to change rules and devices. With some feedback the developer could be encourage to restore backwards compatibility. So share your opinion in the github discussion if you want it back.
- Thomas
Re: State not working??
I Think some decision is already taken but In my opinion:
it is right and reasonable modify all functionality, Mega2.0 is a release candidates not Current stable version.
however…
Could leave the current Switch plugin as is for keep ThomasB and other old users happy but put a message like ”Waring! This plugin is deprecated, please use….”
Develop new plugin like “Switch input”, “Switch output”, “Dimmer” as TD_er propose…
MArco
it is right and reasonable modify all functionality, Mega2.0 is a release candidates not Current stable version.
however…
Could leave the current Switch plugin as is for keep ThomasB and other old users happy but put a message like ”Waring! This plugin is deprecated, please use….”
Develop new plugin like “Switch input”, “Switch output”, “Dimmer” as TD_er propose…
MArco
Re: State not working??
Is it a good idea to remove the 20181204 build from the list, or at least add a big warning about changing functionality of the switch plugin?
I will try to make sure the users of existing rules will not be surprised by the changes.
So either add an event when output change has changed, or proper instructions to change rules, or a flag to keep using old method.
I will try to make sure the users of existing rules will not be surprised by the changes.
So either add an event when output change has changed, or proper instructions to change rules, or a flag to keep using old method.
Re: State not working??
Hmm
I used Switch for relais (output) too, because state is send vie MQTT right after change.
If you use a Dummy like grovkillen said, you have the problem that state is send not directly after change.
Ok ou can change the intervall, but in this case it sends the state every x sec. not only after change. Sending state f.ex. every 5 sec is not practicable.
it will create network load.
Next issue: how to use it via MQTT. Right now you can set directly via gpio command in MQTT. After Sending the command it changes the switch state,
so you see directly the new state.
I think maybe it would be nice having a similiar plugin for input and output, like fra290 said.
Regards Peter
I used Switch for relais (output) too, because state is send vie MQTT right after change.
If you use a Dummy like grovkillen said, you have the problem that state is send not directly after change.
Ok ou can change the intervall, but in this case it sends the state every x sec. not only after change. Sending state f.ex. every 5 sec is not practicable.
it will create network load.
Next issue: how to use it via MQTT. Right now you can set directly via gpio command in MQTT. After Sending the command it changes the switch state,
so you see directly the new state.
I think maybe it would be nice having a similiar plugin for input and output, like fra290 said.
Regards Peter
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: State not working??
You use the switch event to trigger the event toggleLED. This will happen directly, you never should rely on a controller to know the state (my opinion). I don't use the dummy to publish the state, only keep track of it internally. If you want it to be sent you should use the publish command right after the GPIO command.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: State not working??
The "recently" introduced gpio commands :
gpiotoggle,<pin number>
status,gpio,<pin number>
take care of most the issues we used to have in the past given :
a. there is no longer a reason to "condition" (if/else) the current state of a pin in order to toggle it
gpiotoggle,<pin number> does just that. (works for pcf and mcp gpios as well)
and
b. no longer need to declare an output pin as an input switch just to know its state. This alone saves up allot of the just 12 available tasks.
status,gpio,<pin number> does just that. (once you set gpio the first time at after boot)
-D
gpiotoggle,<pin number>
status,gpio,<pin number>
take care of most the issues we used to have in the past given :
a. there is no longer a reason to "condition" (if/else) the current state of a pin in order to toggle it
gpiotoggle,<pin number> does just that. (works for pcf and mcp gpios as well)
and
b. no longer need to declare an output pin as an input switch just to know its state. This alone saves up allot of the just 12 available tasks.
status,gpio,<pin number> does just that. (once you set gpio the first time at after boot)
-D
-D
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: State not working??
I will add these to the rules page in the coming week (or two). Thanks for the heads up
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: State not working??
grovkillen wrote: ↑24 Dec 2018, 18:02
You use the switch event to trigger the event toggleLED. This will happen directly, you never should rely on a controller to know the state (my opinion). I don't use the dummy to publish the state, only keep track of it internally. If you want it to be sent you should use the publish command right after the GPIO command.
Arghhh
Pls give me a little help to understand this one....
....... toggle GPIO-Output directly AND don't use Switch for Output and don*t use dummy. Right?
so how do i publish? only use status,gpio,<pin number> or do i have to use publish ??? what do i have to declare use publish?
... Publish <topic>,<value> ---> publish /esp_0/gpio/12, 0 or 1 ??
Regards Peter
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: State not working??
What do you want to accomplish? Please make a "to the point" description. I have a hard time following your text.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: State not working??
Sorry
As far as i understand, i should not use switch for output (what i did until now).
So how is the best way to get the state of an output in MQTT (f.ex. Relais) when it changes.
because i changed "directly" on the esp via a switch or over MQTT. i have until now following configuration.
Devicetype Name Value Port
switch Light_switch Light_switch io4 ---> for Input
switch Light_RLS state io14 ---> Output
Both with Send to Controller activated
In MQTT i have follwoing Objects :
ESP_Easy_15.Light_switch.state
ESP_Easy_15.gpio.14 (this one is for changing via MQTT)
on Light_switch#Light_switch=1 do
if [Light_RLS#state]=0
gpio,14,1
else
gpio,14,0
endif
endon
if i change via button on ESP, the state is reportet via ESP_Easy_15.Light_switch.state to the MQTT.
if i change the state in the broker i will send the corresponding bit depending on the status ESP_Easy_15.Light_switch.state (0 when it was1; 1 when it was 0) via ESP_Easy_15.gpio.14
in this case after changing the state of ESP_Easy_15.Light_switch.state, the state in MQTT was changed after switching the port.
now my Question. If i should not use switch for output, how do i tell the broker the state after changing?
As far as i understand, i should not use switch for output (what i did until now).
So how is the best way to get the state of an output in MQTT (f.ex. Relais) when it changes.
because i changed "directly" on the esp via a switch or over MQTT. i have until now following configuration.
Devicetype Name Value Port
switch Light_switch Light_switch io4 ---> for Input
switch Light_RLS state io14 ---> Output
Both with Send to Controller activated
In MQTT i have follwoing Objects :
ESP_Easy_15.Light_switch.state
ESP_Easy_15.gpio.14 (this one is for changing via MQTT)
on Light_switch#Light_switch=1 do
if [Light_RLS#state]=0
gpio,14,1
else
gpio,14,0
endif
endon
if i change via button on ESP, the state is reportet via ESP_Easy_15.Light_switch.state to the MQTT.
if i change the state in the broker i will send the corresponding bit depending on the status ESP_Easy_15.Light_switch.state (0 when it was1; 1 when it was 0) via ESP_Easy_15.gpio.14
in this case after changing the state of ESP_Easy_15.Light_switch.state, the state in MQTT was changed after switching the port.
now my Question. If i should not use switch for output, how do i tell the broker the state after changing?
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: State not working??
You should use the publish command and publish whatever your controller want to receive. I do it like this:
Change it to suit your needs.
Code: Select all
On toggleLED Do
If [LED#State]=1
GPIO,12,0
Publish,%sysname%/light,0
Else
GPIO,12,1
Publish,%sysname%/light,1
EndIf
EndOn
On setLED Do
If %eventvalue% > 0
GPIO,12,1
TaskValueSet,10,1
Publish,%sysname%/light,1
Else
GPIO,12,0
TaskValueSet,10,0
Publish,%sysname%/light,1
EndIf
EndOn
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: State not working??
You are the best.
Thanks that is what i missed..........
Re: State not working??
I recently created a task (P001) for every output relay on my house, based on a suggestion I found here on the forum. Just as I finished I found that my device was not changing the task status on local output pin change (stupid me to take so long to realize that, I know).
My problem:
I have a device that keeps loosing wifi and MQTT connection;
It has a push button on a pin that changes an output pin (relay);
Sometimes a publish on change wont work for the reason above (poor wifi);
I need it to periodically send its status to the controller so to keep sync.
I am confused as this is treated in many places here, on github and elsewhere and I cant figure out the actual state of this issue. Can I use a P001 or not?
Can someone please point me the way to accomplish that?
Git Build: | mega-20200703
My problem:
I have a device that keeps loosing wifi and MQTT connection;
It has a push button on a pin that changes an output pin (relay);
Sometimes a publish on change wont work for the reason above (poor wifi);
I need it to periodically send its status to the controller so to keep sync.
I am confused as this is treated in many places here, on github and elsewhere and I cant figure out the actual state of this issue. Can I use a P001 or not?
Can someone please point me the way to accomplish that?
Git Build: | mega-20200703
Re: State not working??
You can try to improve the WiFi stability
Please have a look at these settings:
https://espeasy.readthedocs.io/en/lates ... e-wifi-b-g
I thought I had a checklist in the documentation, but I can't find it.
- Fixed channel
- Force B/G
- Send gratuitous ARP
- Send pings to the node from another host.
- Try rotating the ESP, to see if another antenna orientation may improve stability.
Please have a look at these settings:
https://espeasy.readthedocs.io/en/lates ... e-wifi-b-g
I thought I had a checklist in the documentation, but I can't find it.
- Fixed channel
- Force B/G
- Send gratuitous ARP
- Send pings to the node from another host.
- Try rotating the ESP, to see if another antenna orientation may improve stability.
Re: Stare not working??
Thank You @TD-er! I did most of your checklist, apart from moving the ESP as it is in a very hidden place, behind a wardrobe.
You guys are great and deserve all my thanks.
I will publish my whereabouts so if someone else comes across it we may help each other. Anyway it will help me put things together.
So far I have read through it all again and have reasoned that:
1 - I misunderstood on https://github.com/letscontrolit/ESPEas ... -447281033 that gpio commands would toggle P001 tasks "for now", seems they do not anymore.
2 - It was said here it is not a good idea to use the Dummy device to publish the state. But I cant see another way to periodically publish the state of a pin.
3 - I understand that grovkillen said above (and quoted below) that I cannot use GPIO to change the pin on his solution. I could not understand the reason given (my bad english).
4 - I cannot understand how to send the payload =0 or =1 after the event,SetLED on mqtt.
5 - The code kindly given by grovkillen does not set the dummy device after toggling it. I dont understand why.
If there is anyone out there who can help me I would really appreciate! It is the first time in 2 yrs I ask for help but this is making me crazy. I know I am the one really Dummy here!
You guys are great and deserve all my thanks.
I will publish my whereabouts so if someone else comes across it we may help each other. Anyway it will help me put things together.
So far I have read through it all again and have reasoned that:
1 - I misunderstood on https://github.com/letscontrolit/ESPEas ... -447281033 that gpio commands would toggle P001 tasks "for now", seems they do not anymore.
2 - It was said here it is not a good idea to use the Dummy device to publish the state. But I cant see another way to periodically publish the state of a pin.
3 - I understand that grovkillen said above (and quoted below) that I cannot use GPIO to change the pin on his solution. I could not understand the reason given (my bad english).
4 - I cannot understand how to send the payload =0 or =1 after the event,SetLED on mqtt.
5 - The code kindly given by grovkillen does not set the dummy device after toggling it. I dont understand why.
If there is anyone out there who can help me I would really appreciate! It is the first time in 2 yrs I ask for help but this is making me crazy. I know I am the one really Dummy here!
grovkillen wrote: ↑09 Dec 2018, 15:35 You shouldn't use a switch input device for a LED. If you want to know the state of the LED you should use a dummy device and set it's value using event.
Given that you use task number 10 for a dummy device called "LED" and it's value named "State" you could use this rule:
You can then use this command from whatever way you invoke the command:Code: Select all
On toggleLED Do If [LED#State]=1 GPIO,12,0 Else GPIO,12,1 EndIf EndOn On setLED Do If %eventvalue% > 0 GPIO,12,1 TaskValueSet,10,1 Else GPIO,12,0 TaskValueSet,10,0 EndIf EndOn
Why you cannot use GPIO to do this? Because the system will not know that the GPIO command are not supposed to be used for switching device values.Code: Select all
Event,toggleLED or Event,setLED=1 or Event,setLED=0
Re: State not working??
OK, you've clearly done your research here, but I'm missing one main thing here.
What exactly do you want to achieve here?
Can you describe:
- what triggers GPIO pins
- what action should be taken
- with what should it keep its state in sync?
So instead of directly addressing your points, I guess it is a bit more efficient if we know what you want to achieve here.
What exactly do you want to achieve here?
Can you describe:
- what triggers GPIO pins
- what action should be taken
- with what should it keep its state in sync?
So instead of directly addressing your points, I guess it is a bit more efficient if we know what you want to achieve here.
Re: State not working??
Thank you, I will try to clarify my situation:
I have 2 significant pins on this:
One is on a push button and set with pullup, so I guess it should be active low.
The second one is GPIO-5, connected to a relay active low controlling a light. On homeassistant:
I don't have the task for ESP-Suite2/Closet/State anymore as this is what I am trying to make it right.
The light can be put on by the broker or locally on a single push on GPIO-12. Here are the rules (thank you for your advice on them, but I never understood on the tutorial if I can nest ifs, so I dont try as I have bricked a few MCU messing with rules):
When I use the broker or when I use the web interface->tools->submit everything is fine and ESP-Suite2/Closet/State used to change and report properly, state got updated on the broker.
But when I use the push button (the rules) it does not. So, as I said, when I miss the publish on the Rules the broker cant figure out there was a toggle... That publish of a pushbutton single press was my workaround....
I am trying to get the espeasy to report periodically the state of the pin. That would be the workround of my workaround..
I hope I could explain it this time... Thank you for your time!
Edit: bad spelling.
I have 2 significant pins on this:
One is on a push button and set with pullup, so I guess it should be active low.
Code: Select all
Device: Switch input - Switch
Name: Suite1
Internal PullUp: Yes
Inversed Logic: No
GPIO ⇄ : GPIO-12 (D6)
Switch Type: Switch
Switch Button Type: Push Button Active Low
De-bounce (ms): 20
Doubleclick event: Active only on LOW (EVENT=3)
Doubleclick max. interval (ms): 1000
Send to Controller: no
Values
# Name
1 State
Code: Select all
- platform: mqtt
name: "Closet"
command_topic: "ESP-Suite2/gpio/5"
state_topic: "ESP-Suite2/Closet/State"
payload_on: "0"
payload_off: "1"
availability_topic: "ESP-Suite2/status/LWT"
payload_available: "Connected"
payload_not_available: "Connection Lost"
The light can be put on by the broker or locally on a single push on GPIO-12. Here are the rules (thank you for your advice on them, but I never understood on the tutorial if I can nest ifs, so I dont try as I have bricked a few MCU messing with rules):
Code: Select all
on Suite1#State do
if %eventvalue%=0 or %eventvalue%=1
timerSet,1,1
endif
EndOn
On Rules#Timer=1 do
gpiotoggle,5
Publish ESP-Suite2/Suite1,single
timerSet,1,0
endon
on Suite1#State=3 do
Publish ESP-Suite2/Suite1,double
timerSet,1,0
EndOn
on Suite1#State=11 do
Publish ESP-Suite2/Suite1,long
timerSet,1,0
endon
But when I use the push button (the rules) it does not. So, as I said, when I miss the publish on the Rules the broker cant figure out there was a toggle... That publish of a pushbutton single press was my workaround....
I am trying to get the espeasy to report periodically the state of the pin. That would be the workround of my workaround..
I hope I could explain it this time... Thank you for your time!
Edit: bad spelling.
Re: State not working??
First of all, you can nest if statements. (up-to some level.
I do notice you're using gpiotoggle on the relay.
But I doubt you do know at any moment what the state of the relay is.
So maybe try to keep track of the state somewhere and explicitly set the state, or try to read the state every now and then and send it to the MQTT broker to update the state to others.
But I guess maybe someone else may be more experienced in this, as I don't have really a lot of experience with handling the GPIOs from rules.
I do notice you're using gpiotoggle on the relay.
But I doubt you do know at any moment what the state of the relay is.
So maybe try to keep track of the state somewhere and explicitly set the state, or try to read the state every now and then and send it to the MQTT broker to update the state to others.
But I guess maybe someone else may be more experienced in this, as I don't have really a lot of experience with handling the GPIOs from rules.
Re: State not working??
Great! Thank you! You got me out of the box!
The problem is I was using gpiotggle not the gpio command!
All I had to do was change tat and now State changes accordingly on the button single press!
Now I can go back to the long press 1sec vs timer 1sec dilema...
Amazing job guys keep it on please!
The problem is I was using gpiotggle not the gpio command!
All I had to do was change tat and now State changes accordingly on the button single press!
Code: Select all
on Suite1#State do
if %eventvalue%=0 or %eventvalue%=1
timerSet,1,1
endif
EndOn
On Rules#Timer=1 do
If [Closet#State]=1
GPIO,5,0
Else
GPIO,5,1
EndIf
Publish ESP-Suite2/Suite1,single
timerSet,1,0
endon
on Suite1#State=3 do
Publish ESP-Suite2/Suite1,double
timerSet,1,0
EndOn
on Suite1#State=11 do
Publish ESP-Suite2/Suite1,long
timerSet,1,0
endon
Amazing job guys keep it on please!
Who is online
Users browsing this forum: No registered users and 56 guests