Android tv custom notifications

Doesn't look like it's my day.... :slight_smile:

Thanks for testing it out @pgagne . Leave it with me and I'll work away on it some more over the next few weeks.

No problem, I'm always available to help if needed. Just tag me when you want me to test something. However, I will be unavailable from February 14 to 25.

Thank you again for your work on this project!

1 Like

Yes, thank you very much for your work on this!

1 Like

Hi,
I am looking at getting something like this setup - is this version now working?

Text only notification work actually for me.

1 Like

which tv app and driver are you using?

I'm using this driver: https://raw.githubusercontent.com/sburke781/AndroidTVNotify/mediaOption/AndroidTVNotify_Driver.groovy

I created a virtual device that look like:

And in your app, you can choose the virtual device as destination for your notification like in this example.

On my side, the last thing I want to do is the send a picture in the notification of my doorbell cam.

1 Like

I have just got around to testing this but noticing that my test messages are appearing blank - have you noticed this at any point?

I am seeing this error in the logs

Yeah, indeed. With the latest driver version I have the same problem. I'm not using the latest version of the driver code. That's why it works on my end. However, I have less functionality.

@sburke781 can you help us on this?

I'm not using the latest version of the driver code. That's why it works on my end. However, I have less functionality.

@philpugh and @pgagne

I really should look at this again, but I'm not in a position too for at least another 1-2 weeks. One thing to make sure of is that what I have written matches the target TV app, I know I got these confused before, but would need to look up the details again.

1 Like

Any chance you could send me the content of the driver you are using so I can use the same?

Here is the version i'm currently using:

/**
 *  Android TV Notify Driver
 *
 *  Copyright 2023 Simon Burke
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 *  Change History:
 *
 *    Date        Who            What
 *    ----        ---            ----
 *    2023-08-28  Simon Burke    Original Creation
  */


metadata {
	definition (name: 'Android TV Notify Device', namespace: 'simnet', author: 'Simon Burke') {
        
        capability 'Notification'
        
        //Notification Capability Command
        command 'deviceNotification', [[name:'text', type: 'STRING', description: 'Enter the notification text' ] ]
        
    }    
    
    
  preferences {
    
      // Logging Preferences
      input(name: "DebugLogging", type: "bool", title:"Enable Debug Logging",                   displayDuringSetup: true, defaultValue: false)
      input(name: "WarnLogging",  type: "bool", title:"Enable Warning Logging",                 displayDuringSetup: true, defaultValue: true )
      input(name: "ErrorLogging", type: "bool", title:"Enable Error Logging",                   displayDuringSetup: true, defaultValue: true )
      input(name: "InfoLogging",  type: "bool", title:"Enable Description Text (Info) Logging", displayDuringSetup: true, defaultValue: false)
    
      // TV Preferences
      input(name: "TVIPAddress", type: "string", title:"Android TV IP Address", displayDuringSetup: true, defaultValue: "")
      input(name: "DisplayDuration", type: "number", title:"Duration to Display Notification", displayDuringSetup: true, defaultValue: 30)
      input(name: "Position", type: "number", title:"Position of Notification", displayDuringSetup: true, defaultValue: 0)
      input(name: "DefaultTitle", type: "string", title:"Default Notification Title", displayDuringSetup: true, defaultValue: "Hubitat Notification")
      input(name: "TitleColor", type: "string", title:"Title Color (Hex Value Starting with #)", displayDuringSetup: true, defaultValue: "#")
      input(name: "TitleSize", type: "number", title:"Font Size of Message Title", displayDuringSetup: true, defaultValue: 20)
      input(name: "MessageColor", type: "string", title:"Message Color (Hex Value Starting with #)", displayDuringSetup: true, defaultValue: "#")
      input(name: "MessageSize", type: "number", title:"Font Size of Message Title", displayDuringSetup: true, defaultValue: 20)
      input(name: "BackgroundColor", type: "string", title:"Background Color (Hex Value Starting with #)", displayDuringSetup: true, defaultValue: "#")
    }
}

//Common Methods
void installed() { }

void initialized() { }

/*

curl --header "Content-Type: application/json" --request POST --data @text.json http://192.168.2.x:7979/notify


    {
"duration": 30,
"position": 0,
"title": "Your awesome title",
"titleColor": "#0066cc",
"titleSize": 20,
"message": "What ever you want to say... do it here...",
"messageColor": "#000000",
"messageSize": 14,
"backgroundColor": "#ffffff",
}
*/

//Notification Methods
void deviceNotification(String text) {

  deviceNotification(text, DefaultTitle);
}

void deviceNotification(String text, String title) {

  def headers = [:];
  headers.put("Content-Type", "application/json");
  def bodyJson = "{\"duration\": \"${DisplayDuration}\", \"position\": ${Position}, \"title\": \"${title}\", \"titleColor\": \"${TitleColor}\", \"titleSize\": ${TitleSize}, \"message\": \"${text}\", \"messageColor\": \"${MessageColor}\", \"messageSize\": ${MessageSize}, \"backgroundColor\": \"${BackgroundColor}\" }";
  def postParams = [
        uri: "http://${TVIPAddress}:7979/notify",
        headers: headers,
        contentType: 'application/json',
        body : bodyJson
	]


    try {
        
        httpPost(postParams)
        { resp -> 
            debugLog("deviceNotification: ${resp.data}")
            
        }
            
	}
	catch (Exception e) {
        errorLog("deviceNotification: Unable to send notification: ${e}")
	}
}


//Logging Utility methods
def debugLog(debugMessage) {
	if (DebugLogging == true) {log.debug(debugMessage)}	
}

def errorLog(errorMessage) {
    if (ErrorLogging == true) { log.error(errorMessage)}  
}

def infoLog(infoMessage) {
    if(InfoLogging == true) {log.info(infoMessage)}    
}

def warnLog(warnMessage) {
    if(WarnLogging == true) {log.warn(warnMessage)}    
}

Thanks, I will give this a spin this evening.

@sburke781 - if you need some people to test anything out I am willing to help

1 Like

I'm getting the same error with your version of the driver

Really? Let me share you few detailled screenshot of my setup. Maybe we still have different configuration...

My driver: Nextcloud

This will give something like:

2 Likes

Aaaah so it appears I am using the wrong app on my TV!

Did you sideload pipup or is it from the play store?

I have been using "notifications for android TV" which communicates on port 7676 rather than 7979. I edited the driver to sort the port out.

They were the two apps from memory. There may be another driver around somewhere if you go looking, but I'm not 100% sure...

It's in the play store!

When I searched for Pipup on my Nvidia Shield in Google Play Store, only Notifications for Android TV showed up.

EDIT: I changed Port to 7676 for Notifications for Android TV and a block opens when I send test but getting same errors as @philpugh even copying and pasting @pgagne's version.

Thanks for taking a look and posting what you found. Hopefully I can take a look soon... Or others can do it for me :slightly_smiling_face: