I am having trouble getting an automation to trigger. I have a TCP sensor that I am trying to use in an automation. If I use the “from: ‘off’”, “to: ‘on’” elements it never triggers. If I leave them out it triggers after any change. Am I using the elements wrong?
sensor:
platform: tcp
name: Everyone out
host: 192.168.1.11
port: 8080
payload: “get flag state 14\n”
value_on: ‘on’
value_off: ‘off’
timeout: 5
automation:
alias: “test tts”
trigger:
platform: state
entity_id: sensor.everyone_out
from: ‘off’
to: ‘on’
action:
Are you using a tcp sensor or binary sensor? Are you sure that your payload provokes only the response “on” or “off”? Do you need to include a value template to extract the value on or off from the response? These are just a few ideas I’m having - it could be that the sensor value is never purely “off”, for example, so it will never trigger. Does it work better if you only specify to: and not from:?
Thanks for the reply. Actually the text response for the TCP Sensor is “Set” or “Clear”. But when I tried to use that on the value on: and value off: it didnt make any difference. I went back to the example that I found on the forum. Should I put that back? If I do, would the to: under the trigger be ‘Set’ or still ‘on’?
binary_sensor:
- platform: tcp
name: Everyone out
host: 192.168.1.11
port: 8080
payload: "get flag state 14\n"
value_on: "Set"
timeout: 5
Note that it’s a binary sensor now, not just a sensor. “Value on” is a parameter for tcp binary sensors, not tcp sensors. Now, this state of this binary sensor will be “on” when the returned value is “Set” and off with any other value.
Thanks. Unfortunately i tried it and still no luck. In fact as a binary sensor it doesnt register the correct state on the ui. Does it matter that the payload is text?
Sorry for making you go back and forth but here’s a way to test anyway.
Change the config to:
sensor:
- platform: tcp
name: Everyone out
host: 192.168.1.11
port: 8080
payload: "get flag state 14\n"
timeout: 5
Now the sensor will just display whatever value is returned. So you should be able to see what the values are in both states, if you can simulate them.
Unfortunately it still just doesn’t want to trigger. I am missing something I guess with what is being passed in the text even if it doesn’t show. I tried a template as the message so that it would say one thing if it was ‘Set’ and another if it was ‘else’. The ‘else’ always triggers no matter the value so it just isn’t matching the state value. I can set the value using the STATES in the development tools and it triggers correctly so I am confident in the template. Just at a loss on what exactly is being passed to the TCP sensor. Whatever it is, it is something that can’t be seen. maybe?
Bobby, thanks. I will keep that one in the tool kit for sure!
I was able to look at the transactions using Telnet in Putty and did indeed find that it was putting a line feed after the text response of ‘Set’. Luckily I was able to talk to the person who wrote the interface and get a way to remove the line feed so it only passes the text. Works like a champ now… I hope!
Thanks marthocoo for putting me on the right path and all of the suggestions! Thanks Bobby for your awesome work around.