How to set up value open/close

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
nobody@all
Normal user
Posts: 29
Joined: 09 Apr 2017, 23:27

How to set up value open/close

#1 Post by nobody@all » 20 Mar 2022, 13:11

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.

User avatar
Ath
Normal user
Posts: 3419
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to set up value open/close

#2 Post by Ath » 20 Mar 2022, 14:31

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.
/Ton (PayPal.me)

nobody@all
Normal user
Posts: 29
Joined: 09 Apr 2017, 23:27

Re: How to set up value open/close

#3 Post by nobody@all » 21 Mar 2022, 22:25

thank You! I will try:)

nobody@all
Normal user
Posts: 29
Joined: 09 Apr 2017, 23:27

Re: How to set up value open/close

#4 Post by nobody@all » 29 Mar 2024, 00:18

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 35 times
What I'am missing?
Attachments
switch.jpg
switch.jpg (16.52 KiB) Viewed 33 times

User avatar
Ath
Normal user
Posts: 3419
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to set up value open/close

#5 Post by Ath » 29 Mar 2024, 07:43

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
/Ton (PayPal.me)

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

Re: How to set up value open/close

#6 Post by TD-er » 29 Mar 2024, 11:37

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

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests