I also go messages like this and some others in the same mqtt-topic which I’m not interested in:
e[0;36m[D][sensor:092]: 'ttgocam_1 WiFi Signal': Sending state -24.00000 dB with 0 decimals of accuracye[0m
Since the number is unique for each message I want just the “got image”-part in a separate sensor. I want is to use this to look at the timestamp for last received image to know if my camera sends images or not.
sensor:
- platform: mqtt
name: "Image Length"
state_topic: "your/topic/here"
unit_of_measurement: bytes # not actually sure if this is the right unit and you only need it for graphs. Can be omitted.
value_template: "{{ value|regex_findall_index(find='Got Image: len=(\d+)' }}"
In your example this will return 53798 as the sensor state.
Works as intended and I am now able to automate monitoring and automatic restarts of the camera if it stops sending images after a given amount of time
You might have wanted to lead with that in your original post to minimize people wasting their time coming up with a solution to a problem that you didn’t want and not coming up with a solution for the real problem that you wanted all along.
However, I’m not sure if the sensor you created will do what you want.
Does the message change if the camera stops sending images or does the message just completely stop being sent at all?
If it’s the latter then the last message will always contain “image” and you still won’t know your camera is dead. You will just know that the last message received (whenever that was) contains “image”.
If it’s the former and it still sends messages but they don’t contain “image” then your solution should work.
Yes I know, but I also think it’s a good thing when the title is more precise when searching for solutions in the forum. Templating in HA doesn’t have anything with configuring in ESPhome so i thought it was best to do it separate. I still wanted the other solution the most, but was working on this alternative at the same time. In general I agree with you
Well, it turns out that the board keeps sending data, but stops sending images of some reason. I was thinking that what you are pointing out would be the case, but it’s not. I really want to know why it behave like this, but haven’t found anything other than people having the same problem with no solution.
The PIR, Status and WiFi-sensor keeps sending data and the board is responding to the restart-switch. I even get reboot-info via MQTT-debug under the whole reboot-process.
With my restart-automation it gets back up sending images after just 20 seconds. That results in under 4 minutes loss of images when having the automation triggered by state false with for 3 minutes condition. After some time I will know how low I can set the minutes-condition.