Including the topic with the payload inside the entity node (expression help)

At the minute i’m using an entity node to open and close some blinds. The payload im using is this…

$entity().state ? 1 : 0

Am i able to include different topics for both states within this expression? I’d like to do this as my function node uses the topic to route my open and closed states. (see below). Unfortuantly im not too great with the language and have only got this far from digging through older posts.

[{"id":"fdb67178462dbab1","type":"function","z":"7ca15d706202d7d1","name":"","func":"var topic=msg.topic;\nif (topic==\"test1\"){\nvar msg1 = { payload: 90 };\nvar msg2 = { payload: 90 };\nvar msg3 = { payload: 90 };\nvar msg4 = { payload: 90 };\nvar msg5 = { payload: 90 };\nsetTimeout(function(){node.send([msg1,null,null,null,null]);},10), \nsetTimeout(function(){node.send([null,msg2,null,null,null]);},1200), \nsetTimeout(function(){node.send([null,null,msg3,null,null]);},2400), \nsetTimeout(function(){node.send([null,null,null,msg4,null]);},3600),\nsetTimeout(function(){node.send([null,null,null,null,msg5]);},4800)}\n\nif (topic==\"test2\"){\nvar msg6 = { payload: 190 };\nvar msg7 = { payload: 190 };\nvar msg8 = { payload: 190 };\nvar msg9 = { payload: 190 };\nvar msg10 = { payload: 190 };\nsetTimeout(function(){node.send([msg6,null,null,null,null]);},10), \nsetTimeout(function(){node.send([null,msg7,null,null,null]);},1200), \nsetTimeout(function(){node.send([null,null,msg8,null,null]);},2400), \nsetTimeout(function(){node.send([null,null,null,msg9,null]);},3600),\nsetTimeout(function(){node.send([null,null,null,null,msg10]);},4800)}","outputs":5,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":2300,"wires":[["8aa7a3c6ebdf4de0"],["8aa7a3c6ebdf4de0"],["8aa7a3c6ebdf4de0"],["8aa7a3c6ebdf4de0"],["8aa7a3c6ebdf4de0"]]},{"id":"050a3663ed945e37","type":"ha-entity","z":"7ca15d706202d7d1","name":"Living Room Blinds","server":"5dfbb803.e2fca8","version":2,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"Living Room Blinds"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state ? 1 : 0","outputPayloadType":"jsonata","x":230,"y":2300,"wires":[["fdb67178462dbab1"],["fdb67178462dbab1"]]},{"id":"8aa7a3c6ebdf4de0","type":"debug","z":"7ca15d706202d7d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":2300,"wires":[]},{"id":"5dfbb803.e2fca8","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

Thanks

You can use

{
    "state": $entity().state ? 1:0,
    "topic": "test"
    }

Thanks for getting back! Is it possible to give each state a different topic though?

1 = test
0 = test2

Use the original code in the payload and then use a function after with the following to set the topic.


if (msg.payload == 0) {
  msg.topic = "test0";
} else if (msg.payload == 1) {
  msg.topic = "test1";
} else {
  msg.topic = "null";
}

return msg;