inputswitch state is deprecated - Why? [SOLVED]

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
EDsteve
Normal user
Posts: 61
Joined: 11 May 2018, 21:13

inputswitch state is deprecated - Why? [SOLVED]

#1 Post by EDsteve » 03 Nov 2020, 12:16

Hi,

after some Wifi changes in my house i had to reinstall one of my Sonoff Smart Power socket. I flashed the blank file and after that the new release (ESP_Easy_mega_20201102_normal_ESP8285_1M).

New install and i made exactly the same settings which i have on three other working Sonoffs. I went through all the tabs twice. Settings should work. But every time i try to switch it from Domoticz i get this error:
image_2020-11-03_180256.png
image_2020-11-03_180256.png (24.03 KiB) Viewed 10096 times
All the settings are exactly the same with my other workings Sonoffs. So i have no clue what to do. When i press the physical pushbutton. Then the relay triggers. Hmm.

Rules:

Code: Select all

 on SW#state do
  if [SW#state]=1
   gpio,12,1
  else
   gpio,12,0
  endif
 endon

 on Relay#state do
  if [Relay#state]=1
   gpio,12,1
  else
   gpio,12,0
  endif
 endon
image_2020-11-03_181353.png
image_2020-11-03_181353.png (16.69 KiB) Viewed 10096 times
Is there something i am missing? I just think i ask here before i start spending hours and hours trying different firmware etc...
Thanks ED

EDIT: I just see that i put this threat into the Software section. Maybe not the best choice.
Last edited by EDsteve on 09 Nov 2020, 16:46, edited 1 time in total.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: inputswitch state is deprecated - Why?

#2 Post by ThomasB » 03 Nov 2020, 17:34

Along with other changes to the P001 plugin, InputSwitchStates was removed in the 2020-11-02 release. Perhaps your rules could be rewritten to use events to control the relay. Otherwise the best place to ask on a recommended workaround is in the github issue #2778 that removed that function. See: https://github.com/letscontrolit/ESPEasy/pull/2778

Or if you want to use an earlier Mega release then I suggest reverting back to something from a Sep 2020 Mega release.

BTW, the "depreciated" log error message is misspelled. Took me awhile to find it in the source code because of the typo, but I eventually won the text search battle.

- Thomas

User avatar
EDsteve
Normal user
Posts: 61
Joined: 11 May 2018, 21:13

Re: inputswitch state is deprecated - Why?

#3 Post by EDsteve » 04 Nov 2020, 16:22

Hi,
Perhaps your rules could be rewritten to use events to control the relay
thanks for your answer. Unfortunately i am not a coder. So i am not really sure what you mean by "use events".
According to this ESPeasy reference i already use events, if i understand it correctly:
image_2020-11-04_221058.png
image_2020-11-04_221058.png (37.3 KiB) Viewed 10050 times
Otherwise the best place to ask on a recommended workaround is in the github issue #2778 that removed that function. See: https://github.com/letscontrolit/ESPEasy/pull/2778
It has been removed due to security issues it seems. Sad. So does that mean that these "working examples" will not work any more?
https://www.letscontrolit.com/wiki/inde ... _examples:

Sorry for my limited knowledge. Maybe you can give me a quick example of how to do that with Events. That would be helpful.

Thanks you

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: inputswitch state is deprecated - Why?

#4 Post by ThomasB » 04 Nov 2020, 19:08

Maybe you can give me a quick example of how to do that with Events. That would be helpful.
The general idea is to stop using the "Switch input - Switch" as an GPIO output device, which is what your relay task is doing. This was a convenient thing to do in ESPEasy, but is now forbidden.

I snipped some code from one of my nodes. This example includes rules based push button toggle (momentary press on/off). A boot rule is also used to restore the relay state on a soft reset.

General Info:
* Relay is on GPIO-12. 0=Off, 1=On.
* Push Switch is active low (press sinks GPIO to ground).
* ESPEasy's Home Assistant (openHAB) MQTT controller is used to publish relay state (0/1).

Device Task Info:
* Switch input - Switch task is named BUTTON, value is named press. Internal Pullup, Inverse Logic, Switch Type: Switch, Button Type: Normal, Debounce: 100mS, Send to Controller: Disabled, Interval:0.
* Generic - Dummy Device at task position 6 is named STATEVAR, value #1 is named rlyval.
* No other device tasks are needed.

Code: Select all

// Restore the relay's state during reboot.
on System#Boot do
   if[STATEVAR#rlyval]=1  // Warm boot, relay was previously on.
     event,RelayOn
   else
     event,RelayOff
   endif
endon

// Push Button toggles the Relay
on BUTTON#Press=1 do
  if [STATEVAR#rlyval]=1
     event,RelayOff
  else 
     event,RelayOn
  endif
endon

// Event: Turn on Relay.
on RelayOn do
   TaskValueSet 6,1,1
   gpio,12,1
   Publish %sysname%/STATEVAR/rlyval,[STATEVAR#rlyval]
endon

// Event: Turn off relay.
on RelayOff do
   TaskValueSet 6,1,-1
   gpio,12,0
   Publish %sysname%/STATEVAR/rlyval,[STATEVAR#rlyval]
endon
Tools->Command, MQTT, and http can control the relay using the RelayOn and RelayOff events. Command examples:

Code: Select all

event,RelayOn
event,RelayOff
My rules advice reflects how I like to implement it. But there's more than one way to skin this cat. Maybe someone else will chime in and share an example of their solution.

- Thomas

User avatar
EDsteve
Normal user
Posts: 61
Joined: 11 May 2018, 21:13

Re: inputswitch state is deprecated - Why?

#5 Post by EDsteve » 09 Nov 2020, 10:09

Hi,

sorry for late reply and thanks for your informative post. I am still not sure if i understand your solution.
When i toggle a switch in Domoticz. It will send a MQTT switch-command to ESPeasy. How can that MQTT message trigger the RelayOn/Off event? How does OpenHAB do it?

It works when i enter event,RelayOn in Tools->Commands on ESPeasy... But how can Domoticz trigger it?

Sorry for my limited knowledge. Hope you can give me another hint.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: inputswitch state is deprecated - Why?

#6 Post by TD-er » 09 Nov 2020, 10:40

For switch/gpio integration in Domoticz MQTT, see: https://espeasy.readthedocs.io/en/lates ... t=domoticz

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: inputswitch state is deprecated - Why? [SOLVED]

#7 Post by ThomasB » 09 Nov 2020, 17:28

How can that MQTT message trigger the RelayOn/Off event? How does OpenHAB do it?
My OH2 ".items" file defines the MQTT send/receive actions. For example, here is one that controls AC power (RelayOn and RelayOff) on my 3D printer's ESPEasy node:

Code: Select all

Switch daVinci_AC   "daVinci Relay AC"   <poweroutlet-us> (Equipment) ["Switchable"] {mqtt=">[mosquitto:ESPEZ_daVinci/cmd:command:ON:Event,RelayOn],>[mosquitto:ESPEZ_daVinci/cmd:command:OFF:Event,RelayOff],<[mosquitto:ESPEZ_daVinci/STATEVAR/rlyval:state:OFF:-1],<[mosquitto:ESPEZ_daVinci/STATEVAR/rlyval:state:ON:1]"}
I'm not a Domoticz user, so I can't offer a specific solution. But maybe the link provided by TD-er will help you out.

- Thomas

User avatar
EDsteve
Normal user
Posts: 61
Joined: 11 May 2018, 21:13

Re: inputswitch state is deprecated - Why? [SOLVED]

#8 Post by EDsteve » 10 Nov 2020, 06:10

My OH2 ".items" file defines the MQTT send/receive actions.
Oh i see. That's not so easily possible in Domoticz. I could have converted the message via NodeRed but i just like to keep it simple.
The link from TD-er solved my problem. It seems that Domoticz MQTT helper is mandatory since the new built. Didn't need it before.

All works now but i get error messages in Domoticz when i trigger the switch from Domoticz. Not critical but maybe worth to mention. Haven't really investigated it yet though.
image_2020-11-10_121630.png
image_2020-11-10_121630.png (83.25 KiB) Viewed 9882 times

wim16
Normal user
Posts: 88
Joined: 01 May 2017, 20:35

Re: inputswitch state is deprecated - Why? [SOLVED]

#9 Post by wim16 » 10 Nov 2020, 12:23


Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests