Page 1 of 1

How to set up value open/close

Posted: 20 Mar 2022, 13:11
by nobody@all
Hi. Is it possible using Switch input - Switch to set value Open/Close not 0/1?
I'm trying to do the door lock status sending via mqtt to Nettemp. In nettemp i can receive status open/close.

Re: How to set up value open/close

Posted: 20 Mar 2022, 14:31
by Ath
The use of variables supports formatting like that, as documented here: https://espeasy.readthedocs.io/en/lates ... red-values

so, your rule could use it like this:

Code: Select all

on switch#state do // Adjust switch and state to the name of your Device task
  Publish,topic/goes/here,[switch#state#C#c] // Adjust also when applicable, sends 'Close' and 'Open' ('C' transformation), with first character capitalized, rest in lower case because of the 'c' justification
endon
NB: If you want to send a 'state' (Closed/Open) instead of an 'action' (Close/Open) the 'C' transformation should be changed to 'c'.
If 0 means open, and 1 means close, then the transformation should be prefixed with an exclamation mark, so '!C' or '!c' (no quotes should be used for the transformation in the actual rules code, that's just added for readability)

It is currently not (easily) supported to send a transformed value to a controller, so the Controller checkbox on the task should be disabled, as it is sent from rules now.

Re: How to set up value open/close

Posted: 21 Mar 2022, 22:25
by nobody@all
thank You! I will try:)

Re: How to set up value open/close

Posted: 29 Mar 2024, 00:18
by nobody@all
after almost one year :oops: i have back to this topic.
In link which you posted I found what you meaned.
C: 0 => “CLOSE” 1 => “ OPEN”
c: 0 => “CLOSED” 1 => “ OPEN”

I have been tried something like this:

Code: Select all

on Door_sensor#State do 
  Publish,homedoor_1,Door_sensor,State,[switch#state#C] 
endon
but in [switch#state#C] i have nothing.

Code: Select all

1280172: EVENT: Door_sensor#State=0
1280187: ACT : Publish,homedoor_1,Door_sensor,State,
1284790: EVENT: Door_sensor#State=1
1284801: ACT : Publish,homedoor_1,Door_sensor,State,
mqtt no status.jpg
mqtt no status.jpg (70.03 KiB) Viewed 1231 times
What I'am missing?

Re: How to set up value open/close

Posted: 29 Mar 2024, 07:43
by Ath
nobody@all wrote: 29 Mar 2024, 00:18 after almost one year :oops: i have back to this topic.
2022, that's even 2 years ago :lol:
nobody@all wrote: 29 Mar 2024, 00:18

Code: Select all

on Door_sensor#State do 
  Publish,homedoor_1,Door_sensor,State,[switch#state#C] 
endon
but in [switch#state#C] i have nothing.
...
What I'am missing?
Well, that's to be expected, your switch is called Door_sensor...
This should work:

Code: Select all

on Door_sensor#State do 
  Publish,homedoor_1,Door_sensor,State,[Door_sensor#state#C] 
endon

Re: How to set up value open/close

Posted: 29 Mar 2024, 11:37
by TD-er
You might also need to use quotes as the " OPEN" has a space in it.
And you have too many commas for the MQTT topic.
Typically you have to use / as separator for topic levels.

Code: Select all

on Door_sensor#State do 
  Publish,homedoor_1/Door_sensor/State,"[Door_sensor#state#C]"
endon
Maybe this is better:

Code: Select all

on Door_sensor#State do
  if %eventvalue%=0
    Publish,homedoor_1/Door_sensor/State,CLOSE
  else
    Publish,homedoor_1/Door_sensor/State,OPEN
  endif
endon

Re: How to set up value open/close

Posted: 31 Mar 2024, 00:36
by nobody@all
I finally know why my wife is always angry at me - I think I'm doing it quickly but in real two year passed like a one day :D

this code

Code: Select all

on Door_sensor#State do
  if %eventvalue%=0
    Publish,homedoor_1/Door_sensor/State,CLOSE
  else
    Publish,homedoor_1/Door_sensor/State,OPEN
  endif
endon
work great. thank You :)

Re: How to set up value open/close

Posted: 31 Mar 2024, 00:53
by TD-er
You're welcome :)